将pdm中的字段名称或者备注写入oracle数据库的备注字段(源码)

8 篇文章 1 订阅
2 篇文章 0 订阅
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Xml;
using System.Collections.Generic;
using System.Xml.XPath;
public partial class crbbg_pdm : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        GetDataBaseTable();//将pdm文件中字段的注释或者中文名,同步到数据库对应字段的注释里。 
    }
   

        public void GetDataBaseTable()
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load("C://Users//1.pdm");
            XmlNamespaceManager xmlnsManager = new XmlNamespaceManager(xmlDoc.NameTable);
            xmlnsManager.AddNamespace("a", "attribute");
            xmlnsManager.AddNamespace("c", "collection");
            xmlnsManager.AddNamespace("o", "object");
            XmlNode xnTables = xmlDoc.SelectSingleNode("//" + "c:Tables", xmlnsManager);
 
            List<PDMTableInfo> Tables = new List<PDMTableInfo>();
            foreach (XmlNode xnTable in xnTables.ChildNodes)
            {
                Tables.Add(GetTable(xnTable));
            }
          //comment on column OA_GZLC.YXQ is 'aa';
            AddCommnet(Tables);
         
        }
        private void AddCommnet(List<PDMTableInfo> Tables)
        {
            foreach (PDMTableInfo lm_info in Tables)
            {
                using (CDataBase cdb = new CDataBase("ylgz3"))
                {
                    string sql3 = "select table_name from all_tab_comments where table_name='" + lm_info.Code.ToUpper() + "' and  comments is null";
                    object lo_isnull = cdb.ExeSQL(sql3);
                    if (lo_isnull != DBNull.Value && lo_isnull != null)
                    {
                        string ls_commnt = "";
                        if (!string.IsNullOrEmpty(lm_info.Comment))
                            ls_commnt = lm_info.Comment;
                        else
                            ls_commnt = lm_info.Name;
                        string sql2 = "comment on table " + lm_info.Code + " is '" + Replace(lm_info.Name) + "' ";
                        try
                        {
                            cdb.ExeSQL(sql2);
                            cdb.Commit();
                        }
                        catch
                        {
                            continue;
                        }
                    }
                    if (lm_info.Columns != null)
                    {
                        foreach (PDMColumnInfo col in lm_info.Columns)
                        {
                            string ls_commnt = "";
                            if (!string.IsNullOrEmpty(col.Comment))
                                ls_commnt = col.Comment;
                            else
                                ls_commnt = col.Name;
                            string sql = "select * from user_col_comments where table_name='" + lm_info.Code.ToUpper()  + "' and  comments is null";
                            DataTable dt = cdb.SetDataTable(sql);
                            foreach (DataRow dr in dt.Rows)
                            {
                                if (dr["column_name"].ToString() == col.Code.ToUpper() && (dr["comments"] == null || dr["comments"] == DBNull.Value))
                                {

                                    string sql1 = "comment on column " + lm_info.Code + "." + col.Code + " is '" + Replace(ls_commnt) + "'";
                                    cdb.ExeSQL(sql1);
                                    cdb.Commit();
                                }
                            }
                        }
                    }
                }
              
            }
        }
        public string Replace(string ls_commnt)
        {
          return  Util.f_replacehtml(ls_commnt);
        }
        public class TableInfo
        {
            public TableInfo()
            {
            }
            string tableId;

            public string TableId
            {
                get { return tableId; }
                set { tableId = value; }
            }
            string objectID;

            public string ObjectID
            {
                get { return objectID; }
                set { objectID = value; }
            }
            string name;

            public string Name
            {
                get { return name; }
                set { name = value; }
            }
            string code;

            public string Code
            {
                get { return code; }
                set { code = value; }
            }
            int creationDate;

            public int CreationDate
            {
                get { return creationDate; }
                set { creationDate = value; }
            }
            string creator;

            public string Creator
            {
                get { return creator; }
                set { creator = value; }
            }
            int modificationDate;

            public int ModificationDate
            {
                get { return modificationDate; }
                set { modificationDate = value; }
            }
            string modifier;

            public string Modifier
            {
                get { return modifier; }
                set { modifier = value; }
            }
            string comment;

            public string Comment
            {
                get { return comment; }
                set { comment = value; }
            }

            string physicalOptions;

            public string PhysicalOptions
            {
                get { return physicalOptions; }
                set { physicalOptions = value; }
            }


            IList<ColumnInfo> columns;

            public IList<ColumnInfo> Columns
            {
                get { return columns; }
            }

            IList<PdmKey> keys;

            public IList<PdmKey> Keys
            {
                get { return keys; }
            }

            public void AddColumn(ColumnInfo mColumn)
            {
                if (columns == null)
                    columns = new List<ColumnInfo>();
                columns.Add(mColumn);
            }

            public void AddKey(PdmKey mKey)
            {
                if (keys == null)
                    keys = new List<PdmKey>();
                keys.Add(mKey);
            }
        }
        public class PdmKey
        {
            public PdmKey()
            {
            }

            string keyId;

            public string KeyId
            {
                get { return keyId; }
                set { keyId = value; }
            }
            string objectID;

            public string ObjectID
            {
                get { return objectID; }
                set { objectID = value; }
            }
            string name;

            public string Name
            {
                get { return name; }
                set { name = value; }
            }
            string code;

            public string Code
            {
                get { return code; }
                set { code = value; }
            }
            int creationDate;

            public int CreationDate
            {
                get { return creationDate; }
                set { creationDate = value; }
            }
            string creator;

            public string Creator
            {
                get { return creator; }
                set { creator = value; }
            }
            int modificationDate;

            public int ModificationDate
            {
                get { return modificationDate; }
                set { modificationDate = value; }
            }
            string modifier;

            public string Modifier
            {
                get { return modifier; }
                set { modifier = value; }
            }

            IList<ColumnInfo> columns;

            public IList<ColumnInfo> Columns
            {
                get { return columns; }
            }

            public void AddColumn(ColumnInfo mColumn)
            {
                if (columns == null)
                    columns = new List<ColumnInfo>();
                columns.Add(mColumn);
            }
        }

        //初始化"o:Table"的节点
        private PDMTableInfo GetTable(XmlNode xnTable)
        {
            PDMTableInfo mTable = new PDMTableInfo();
            XmlElement xe = (XmlElement)xnTable;
            mTable.TableId = xe.GetAttribute("Id");
            XmlNodeList xnTProperty = xe.ChildNodes;
            foreach (XmlNode xnP in xnTProperty)
            {
                switch (xnP.Name)
                {
                    case "a:ObjectID": mTable.ObjectID = xnP.InnerText;
                        break;
                    case "a:Name": mTable.Name = xnP.InnerText;
                        break;
                    case "a:Code": mTable.Code = xnP.InnerText;
                        break;
                    case "a:CreationDate": mTable.CreationDate = Convert.ToInt32(xnP.InnerText);
                        break;
                    case "a:Creator": mTable.Creator = xnP.InnerText;
                        break;
                    case "a:ModificationDate": mTable.ModificationDate = Convert.ToInt32(xnP.InnerText);
                        break;
                    case "a:Modifier": mTable.Modifier = xnP.InnerText;
                        break;
                    case "a:Comment": mTable.Comment = xnP.InnerText;
                        break;
                    case "a:PhysicalOptions": mTable.PhysicalOptions = xnP.InnerText;
                        break;
                    case "c:Columns": InitColumns(xnP, mTable);
                        break;
                    case "c:Keys": InitKeys(xnP, mTable);
                        break;
                }
            }
            return mTable;
        }
        //初始化"c:Columns"的节点
        private void InitColumns(XmlNode xnColumns, PDMTableInfo pTable)
        {
            foreach (XmlNode xnColumn in xnColumns)
            {
                pTable.AddColumn(GetColumn(xnColumn));
            }
        }
 
        //初始化c:Keys"的节点
        private void InitKeys(XmlNode xnKeys, PDMTableInfo pTable)
        {
            foreach (XmlNode xnKey in xnKeys)
            {
                pTable.AddKey(GetKey(xnKey));
            }
        }
        public class ColumnInfo
        {
            public ColumnInfo()
            { }

            string columnId;

            public string ColumnId
            {
                get { return columnId; }
                set { columnId = value; }
            }
            string objectID;

            public string ObjectID
            {
                get { return objectID; }
                set { objectID = value; }
            }
            string name;

            public string Name
            {
                get { return name; }
                set { name = value; }
            }
            string code;

            public string Code
            {
                get { return code; }
                set { code = value; }
            }
            int creationDate;

            public int CreationDate
            {
                get { return creationDate; }
                set { creationDate = value; }
            }
            string creator;

            public string Creator
            {
                get { return creator; }
                set { creator = value; }
            }
            int modificationDate;

            public int ModificationDate
            {
                get { return modificationDate; }
                set { modificationDate = value; }
            }
            string modifier;

            public string Modifier
            {
                get { return modifier; }
                set { modifier = value; }
            }
            string comment;

            public string Comment
            {
                get { return comment; }
                set { comment = value; }
            }
            string dataType;

            public string DataType
            {
                get { return dataType; }
                set { dataType = value; }
            }
            string length;

            public string Length
            {
                get { return length; }
                set { length = value; }
            }
            //是否自增量
            bool identity;

            public bool Identity
            {
                get { return identity; }
                set { identity = value; }
            }
            bool mandatory;
            //禁止为空
            public bool Mandatory
            {
                get { return mandatory; }
                set { mandatory = value; }
            }
            string extendedAttributesText;
            //扩展属性
            public string ExtendedAttributesText
            {
                get { return extendedAttributesText; }
                set { extendedAttributesText = value; }
            }
            string physicalOptions;

            public string PhysicalOptions
            {
                get { return physicalOptions; }
                set { physicalOptions = value; }
            }
        }

        private PDMColumnInfo GetColumn(XmlNode xnColumn)
        {
            PDMColumnInfo mColumn = new PDMColumnInfo();
            XmlElement xe = (XmlElement)xnColumn;
            mColumn.ColumnId = xe.GetAttribute("Id");
            XmlNodeList xnCProperty = xe.ChildNodes;
            foreach (XmlNode xnP in xnCProperty)
            {
                switch (xnP.Name)
                {
                    case "a:ObjectID": mColumn.ObjectID = xnP.InnerText;
                        break;
                    case "a:Name": mColumn.Name = xnP.InnerText;
                        break;
                    case "a:Code": mColumn.Code = xnP.InnerText;
                        break;
                    case "a:CreationDate": mColumn.CreationDate = Convert.ToInt32(xnP.InnerText);
                        break;
                    case "a:Creator": mColumn.Creator = xnP.InnerText;
                        break;
                    case "a:ModificationDate": mColumn.ModificationDate = Convert.ToInt32(xnP.InnerText);
                        break;
                    case "a:Modifier": mColumn.Modifier = xnP.InnerText;
                        break;
                    case "a:Comment": mColumn.Comment = xnP.InnerText;
                        break;
                    case "a:DataType": mColumn.DataType = xnP.InnerText;
                        break;
                    case "a:Length": mColumn.Length = xnP.InnerText;
                        break;
                    case "a:Identity": mColumn.Identity = ConvertToBooleanPG(xnP.InnerText);
                        break;
                    case "a:Mandatory": mColumn.Mandatory = ConvertToBooleanPG(xnP.InnerText);
                        break;
                    case "a:PhysicalOptions": mColumn.PhysicalOptions = xnP.InnerText;
                        break;
                    case "a:ExtendedAttributesText": mColumn.ExtendedAttributesText = xnP.InnerText;
                        break;
                }
            }
            return mColumn;
        }
 
        private PDMKey GetKey(XmlNode xnKey)
        {
            PDMKey mKey = new PDMKey();
            XmlElement xe = (XmlElement)xnKey;
            mKey.KeyId = xe.GetAttribute("Id");
            XmlNodeList xnKProperty = xe.ChildNodes;
            foreach (XmlNode xnP in xnKProperty)
            {
                switch (xnP.Name)
                {
                    case "a:ObjectID": mKey.ObjectID = xnP.InnerText;
                        break;
                    case "a:Name": mKey.Name = xnP.InnerText;
                        break;
                    case "a:Code": mKey.Code = xnP.InnerText;
                        break;
                    case "a:CreationDate": mKey.CreationDate = Convert.ToInt32(xnP.InnerText);
                        break;
                    case "a:Creator": mKey.Creator = xnP.InnerText;
                        break;
                    case "a:ModificationDate": mKey.ModificationDate = Convert.ToInt32(xnP.InnerText);
                        break;
                    case "a:Modifier": mKey.Modifier = xnP.InnerText;
                        break;
                    //还差 <c:Key.Columns>
                }
            }
            return mKey;
        }
 
        private static Boolean ConvertToBooleanPG(Object obj)
        {
            if (obj != null)
            {
                string mStr = obj.ToString();
                mStr = mStr.ToLower();
                if ((mStr.Equals("y") || mStr.Equals("1")) || mStr.Equals("true"))
                {
                    return true;
                }
            }
            return false;
        }
    } 


public class PDMColumnInfo
    {
        public PDMColumnInfo()
        { }
 
        string columnId;
 
        public string ColumnId
        {
            get { return columnId; }
            set { columnId = value; }
        }
        string objectID;
 
        public string ObjectID
        {
            get { return objectID; }
            set { objectID = value; }
        }
        string name;
 
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        string code;
 
        public string Code
        {
            get { return code; }
            set { code = value; }
        }
        int creationDate;
 
        public int CreationDate
        {
            get { return creationDate; }
            set { creationDate = value; }
        }
        string creator;
 
        public string Creator
        {
            get { return creator; }
            set { creator = value; }
        }
        int modificationDate;
 
        public int ModificationDate
        {
            get { return modificationDate; }
            set { modificationDate = value; }
        }
        string modifier;
 
        public string Modifier
        {
            get { return modifier; }
            set { modifier = value; }
        }
        string comment;
 
        public string Comment
        {
            get { return comment; }
            set { comment = value; }
        }
        string dataType;
 
        public string DataType
        {
            get { return dataType; }
            set
            {
                if (value.Contains("nvarchar") || value.Contains("varchar"))
                {
                    value = "string";
                }
                if (value.Contains("money"))
                {
                    value = "decimal";
                }
                dataType = value; 
            }
        }
        string length;
 
        public string Length
        {
            get { return length; }
            set { length = value; }
        }
        //是否自增量
        bool identity;
 
        public bool Identity
        {
            get { return identity; }
            set { identity = value; }
        }
        bool mandatory;
        //禁止为空
        public bool Mandatory
        {
            get { return mandatory; }
            set { mandatory = value; }
        }
        string extendedAttributesText;
        //扩展属性
        public string ExtendedAttributesText
        {
            get { return extendedAttributesText; }
            set { extendedAttributesText = value; }
        }
        string physicalOptions;
 
        public string PhysicalOptions
        {
            get { return physicalOptions; }
            set { physicalOptions = value; }
        }
    } 
  

public class PDMKey
    {
        public PDMKey()
        {
        }
 
        string keyId;
 
        public string KeyId
        {
            get { return keyId; }
            set { keyId = value; }
        }
        string objectID;
 
        public string ObjectID
        {
            get { return objectID; }
            set { objectID = value; }
        }
        string name;
 
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        string code;
 
        public string Code
        {
            get { return code; }
            set { code = value; }
        }
        int creationDate;
 
        public int CreationDate
        {
            get { return creationDate; }
            set { creationDate = value; }
        }
        string creator;
 
        public string Creator
        {
            get { return creator; }
            set { creator = value; }
        }
        int modificationDate;
 
        public int ModificationDate
        {
            get { return modificationDate; }
            set { modificationDate = value; }
        }
        string modifier;
 
        public string Modifier
        {
            get { return modifier; }
            set { modifier = value; }
        }
 
        IList<PDMColumnInfo> columns;
 
        public IList<PDMColumnInfo> Columns
        {
            get { return columns; }
        }
 
        public void AddColumn(PDMColumnInfo mColumn)
        {
            if (columns == null)
                columns = new List<PDMColumnInfo>();
            columns.Add(mColumn);
        }
    } 
  

public class PDMTableInfo
    {
        public PDMTableInfo()
        {
        }
        string tableId;
 
        public string TableId
        {
            get { return tableId; }
            set { tableId = value; }
        }
        string objectID;
 
        public string ObjectID
        {
            get { return objectID; }
            set { objectID = value; }
        }
        string name;
 
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        string code;
 
        public string Code
        {
            get { return code; }
            set { code = value; }
        }
        int creationDate;
 
        public int CreationDate
        {
            get { return creationDate; }
            set { creationDate = value; }
        }
        string creator;
 
        public string Creator
        {
            get { return creator; }
            set { creator = value; }
        }
        int modificationDate;
 
        public int ModificationDate
        {
            get { return modificationDate; }
            set { modificationDate = value; }
        }
        string modifier;
 
        public string Modifier
        {
            get { return modifier; }
            set { modifier = value; }
        }
        string comment;
 
        public string Comment
        {
            get { return comment; }
            set { comment = value; }
        }
 
        string physicalOptions;
 
        public string PhysicalOptions
        {
            get { return physicalOptions; }
            set { physicalOptions = value; }
        }
 
 
        IList<PDMColumnInfo> columns;
 
        public IList<PDMColumnInfo> Columns
        {
            get { return columns; }
        }
 
        IList<PDMKey> keys;
 
        public IList<PDMKey> Keys
        {
            get { return keys; }
        }
 
        public void AddColumn(PDMColumnInfo mColumn)
        {
            if (columns == null)
                columns = new List<PDMColumnInfo>();
            columns.Add(mColumn);
        }
 
        public void AddKey(PDMKey mKey)
        {
            if (keys == null)
                keys = new List<PDMKey>();
            keys.Add(mKey);
        }
    }

其中,f_replacehtml是字符串替换函数,代码如下:

 /// <summary>
        /// 删除html脚本 2016-6-20 liushi
        /// </summary>
        /// <param name="Htmlstring"></param>
        /// <returns></returns>
        public static string f_replacehtml(string Htmlstring)
        {
            Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);

            //删除HTML

            Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);

            Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);

            Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);

            Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);

            Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);

            Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);

            Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);

            Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);

            Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);

            Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);

            Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);

            Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);

            Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);

            Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase);

            Htmlstring = Htmlstring.Replace("<", "");

            Htmlstring = Htmlstring.Replace(">", "");

            Htmlstring = Htmlstring.Replace("\"", "“");

            Htmlstring = Htmlstring.Replace("\'", "’");

            //Htmlstring = Htmlstring.Replace("—", "");

            //Htmlstring = Htmlstring.Replace("…", "");
            Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();

            return Htmlstring;

        }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值