最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#遞歸應(yīng)用之實(shí)現(xiàn)JS文件的自動(dòng)引用

 更新時(shí)間:2023年03月11日 14:37:19   作者:hztech  
這篇文章主要為大家詳細(xì)介紹了C#如何利用遞歸實(shí)現(xiàn)JS文件的自動(dòng)引用的功能,文中的示例代碼講解詳細(xì),具有一定的參考價(jià)值,需要的可以參考一下

背景

兩張表,分別是 :sys_tbl,和 sys_field,其中:sys_tbl 是系統(tǒng)所有表的信息,包含兩個(gè)字段 :code(表名),name(表描述信息);sys_fld 是記錄第張表中的字段 的名稱(field)和描述信息(table) , 

截圖如下:

sys_tbl

其中,字段 名稱包含對(duì)其它名稱(對(duì)象) 的引用,寫法為:表名(去除下劃線)_引用字段 ,如:einventory_cinvcode,就是對(duì)表 e_inventory 中字段 cinvcode的引用。

每張表都在系統(tǒng) 中對(duì)應(yīng)有不同功能的js文件(模塊)如: 編輯窗體(dialog類型),跨域選擇窗體(field)類型等

需求

在一個(gè)綜合的頁(yè)面中,會(huì)對(duì)其它對(duì)象進(jìn)行引用(依賴),而這種引用最終體現(xiàn)在對(duì)js文件的包含。同時(shí)被引用的js 文件(一級(jí)引用)還有自已關(guān)聯(lián)對(duì)象(二級(jí)引用).....如此下去,直到N 級(jí)引用。

所以現(xiàn)在需要逐層找到對(duì)象的引用,直到最后不依賴任何對(duì)象為止,并把這些js文件生成引用包含路徑(不重復(fù))

分析

1、返回結(jié)果類型

得到這些js引用,不能重復(fù),但是對(duì)象之間引用是可以存在交叉的,在整個(gè)引用鏈條上,同一個(gè)對(duì)象會(huì)被 多個(gè)對(duì)象引用,所以簡(jiǎn)單的字符串?dāng)?shù)組是避免不了重復(fù)的。但是在C#中的HashSet可以做到不重復(fù),同時(shí)這個(gè)去重工作是自動(dòng)完成的,所以存結(jié)果如果是簡(jiǎn)單的value類型,用 HashSet就可以,但是因?yàn)樽侄沃斜淼男畔⒁呀?jīng)被格式化過(guò),所以還要把格式化之前的表名稱取出與字段對(duì)應(yīng),所以需要一個(gè)key-value類型的數(shù)據(jù) ,那就是 Dictionary<string, string> 了。

2、算法選擇

因?yàn)椴檎乙茫菍訉舆M(jìn)行的,而且下一層引用的要用到上一層的引用結(jié)果,所以這里選擇遞歸算法

代碼實(shí)現(xiàn)

聲明一個(gè)全局變量,記錄所有的表與字段的對(duì)應(yīng)的數(shù)據(jù),因?yàn)樾枰_保數(shù)據(jù)key 唯一性所以選擇Dicctionary類型

/// <summary>
        /// define the gloable parameter to save the rel obj data
        /// </summary>
        public static Dictionary<string, string> <strong>deepRef </strong>= new Dictionary<string, string>();

入口函數(shù),完成準(zhǔn)備工作,(數(shù)據(jù)庫(kù)連接,參數(shù)準(zhǔn)備)

/// <summary>
        /// 通過(guò)表的字段 獲取相關(guān)的引用字段依賴的對(duì)象 直到?jīng)]有依賴為止
        /// </summary>
        /// <param name="headField">表字段列表</param>
        /// <returns></returns>
        public static Dictionary<string,string>  getRelRef(List<IniItemsTableItem> headField)
        {
            HashSet<string> refset = new HashSet<string>();
           // HashSet<string> refset_result = new HashSet<string>();
            foreach (var item in headField)
            {
                if (!item.controlType.StartsWith("hz_"))// is not the field of  reference
                {
                    continue;
                }
                string[] fieldarr = item.dataIndex.Split('_');//the constructor is :[tabble]_[field]

                refset.Add(fieldarr[0]);//the first prefix

            }
            dataOperate dao = new dataOperate();
            dao.DBServer = "info";
            SqlConnection conn = dao.createCon();
            try
            {
                if (refset.Count > 0)
                {
                    
                    if (conn.State != ConnectionState.Open)
                        conn.Open();//open connection
                    deepRef = new Dictionary<string, string>();//clear the relation obj data
                    getRef(conn, refset);
                 

                }
                return deepRef;
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
            }

        }

遞歸函數(shù),最終完成在數(shù)據(jù)庫(kù)中獲取字段依賴的對(duì)象的獲取

/// <summary>
        /// get the relation obj 
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="ref_field"></param>
        /// <returns></returns>
        public static HashSet<string> <strong>getRef</strong>(SqlConnection conn, HashSet<string> ref_field)
        {
            HashSet<string> refset = new HashSet<string>();

            string refstr = string.Join("','", ref_field);
            if (refstr != "")
            {
                refstr = "'" + refstr + "'";

                string sql = "SELECT dbo.GetSplitOfIndex(b.[field],'_',1) as refcode,a.[code]  FROM   (  select   replace(code,'_','') as uncode,* from     [SevenWOLDev].[dbo].[sys_tbl_view] )   as a inner join [SevenWOLDev].[dbo].[sys_fld_view]  as b    on a.uncode=dbo.GetSplitOfIndex(b.[field],'_',1)    where replace([table],'_','') in (" + refstr + ") and uitype='ref'";
                //get dataset relation obj
                DataSet ds = dataOperate.getDataset(conn, sql);
                if (ds != null && ds.Tables.Count > 0)
                {
                    DataTable dt = ds.Tables[0];
                    if (dt.Rows.Count > 0)
                    {
                        //rel ref exists
                        for (int k = 0; k < dt.Rows.Count; k++)
                        {
                            string vt = dt.Rows[k].ItemArray[0].ToString();
                             string vv = dt.Rows[k].ItemArray[1].ToString();
                            refset.Add(vt);//save current ref
                            if(!<strong>deepRef</strong>.ContainsKey(vt))
                                <strong>deepRef</strong>.Add(vt, vv);// save all ref

                             
                        }
                        if (refset.Count > 0)// get the ref successfully
                        {
                            //recursion get
                            getRef(conn, refset);
                        }

                    }

                }

            }
            else
            { 
                //no ref
            }
            return refset;
        }

對(duì)函數(shù)進(jìn)行調(diào)用,并組織出js文件引用路徑

Dictionary<string,string> deepRef = ExtjsFun.getRelRef(HeadfieldSetup);
            if (deepRef != null)
            {
                foreach (var s in deepRef)
                {
                    string tem_module = "";
                    tem_module = s.Value;
                    string[] moduleArr = tem_module.Split('_');
                    if (tem_module.IndexOf("_") >= 0)
                        tem_module = moduleArr[1];//module name for instance: p_machine ,the module is “machine” unless not included the underscore
                    string fieldkind = "dialog";
                    jslist.Add(MyComm.getFirstUp(tem_module) + "/" + ExtjsFun.GetJsModuleName(tem_module, s.Value, fieldkind) + ".js");
                    fieldkind = "field";
                    jslist.Add(MyComm.getFirstUp(tem_module) + "/" + ExtjsFun.GetJsModuleName(tem_module, s.Value, fieldkind) + ".js");
                }
            }

最終結(jié)果 如下:

<script src="../../dept/demoApp/scripts/Sprice/SpriceE_spriceGridfield.js" type="text/javascript"></script>
      <script src="../../dept/demoApp/scripts/Org/OrgE_orgDialog.js" type="text/javascript"></script>
      <script src="../../dept/demoApp/scripts/Supplier/SupplierOa_supplierDialog.js" type="text/javascript"></script>
      <script src="../../dept/demoApp/scripts/Supplier/SupplierOa_supplierField.js" type="text/javascript"></script>
      <script src="../../dept/demoApp/scripts/Unit/UnitE_unitDialog.js" type="text/javascript"></script>
      <script src="../../dept/demoApp/scripts/Unit/UnitE_unitField.js" type="text/javascript"></script>
      <script src="../../dept/demoApp/scripts/Wh/WhWh_whDialog.js" type="text/javascript"></script>
      <script src="../../dept/demoApp/scripts/Wh/WhWh_whField.js" type="text/javascript"></script>
      <script src="../../dept/demoApp/scripts/Mold/MoldP_moldDialog.js" type="text/javascript"></script>
      <script src="../../dept/demoApp/scripts/Mold/MoldP_moldField.js" type="text/javascript"></script>
      <script src="../../dept/demoApp/scripts/Suppliercategory/SuppliercategoryOa_suppliercategoryDialog.js" type="text/javascript"></script>
      <script src="../../dept/demoApp/scripts/Suppliercategory/SuppliercategoryOa_suppliercategoryField.js" type="text/javascript"></script>
      <script src="../../dept/demoApp/scripts/Bank/BankOa_bankDialog.js" type="text/javascript"></script>
      <script src="../../dept/demoApp/scripts/Bank/BankOa_bankField.js" type="text/javascript"></script>
      <script src="../../dept/demoApp/scripts/Machine/MachineP_machineDialog.js" type="text/javascript"></script>
      <script src="../../dept/demoApp/scripts/Machine/MachineP_machineField.js" type="text/javascript"></script>
      <script src="../../dept/demoApp/scripts/Inventory/InventoryE_inventoryDialog.js" type="text/javascript"></script>
      <script src="../../dept/demoApp/scripts/Basedocment/BasedocmentOa_basedocmentDialog.js" type="text/javascript"></script>
      <script src="../../dept/demoApp/scripts/Basedocment/BasedocmentOa_basedocmentField.js" type="text/javascript"></script>
      <script src="../../dept/demoApp/scripts/Basedoctype/BasedoctypeOa_basedoctypeDialog.js" type="text/javascript"></script>
      <script src="../../dept/demoApp/scripts/Basedoctype/BasedoctypeOa_basedoctypeField.js" type="text/javascript"></script>
      <script src="../../dept/demoApp/scripts/Tax/TaxE_taxDialog.js" type="text/javascript"></script>
      <script src="../../dept/demoApp/scripts/Tax/TaxE_taxField.js" type="text/javascript"></script>

完事代碼如下:

/// <summary>
        /// define the gloable parameter to save the rel obj data
        /// </summary>
        public static Dictionary<string, string> deepRef = new Dictionary<string, string>();
        /// <summary>
        /// 通過(guò)表的字段 獲取相關(guān)的引用字段依賴的對(duì)象 直到?jīng)]有依賴為止
        /// </summary>
        /// <param name="headField">表字段列表</param>
        /// <returns></returns>
        public static Dictionary<string,string>  getRelRef(List<IniItemsTableItem> headField)
        {
            HashSet<string> refset = new HashSet<string>();
           // HashSet<string> refset_result = new HashSet<string>();
            foreach (var item in headField)
            {
                if (!item.controlType.StartsWith("hz_"))// is not the field of  reference
                {
                    continue;
                }
                string[] fieldarr = item.dataIndex.Split('_');//the constructor is :[tabble]_[field]

                refset.Add(fieldarr[0]);//the first prefix

            }
            dataOperate dao = new dataOperate();
            dao.DBServer = "info";
            SqlConnection conn = dao.createCon();
            try
            {
                if (refset.Count > 0)
                {
                    
                    if (conn.State != ConnectionState.Open)
                        conn.Open();//open connection
                    deepRef = new Dictionary<string, string>();//clear the relation obj data
                    getRef(conn, refset);
                 

                }
                return deepRef;
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
            }


            

        }
       
        /// <summary>
        /// get the relation obj 
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="ref_field"></param>
        /// <returns></returns>
        public static HashSet<string> getRef(SqlConnection conn, HashSet<string> ref_field)
        {
            HashSet<string> refset = new HashSet<string>();

            string refstr = string.Join("','", ref_field);
            if (refstr != "")
            {
                refstr = "'" + refstr + "'";

                string sql = "SELECT dbo.GetSplitOfIndex(b.[field],'_',1) as refcode,a.[code]  FROM   (  select   replace(code,'_','') as uncode,* from     [SevenWOLDev].[dbo].[sys_tbl_view] )   as a inner join [SevenWOLDev].[dbo].[sys_fld_view]  as b    on a.uncode=dbo.GetSplitOfIndex(b.[field],'_',1)    where replace([table],'_','') in (" + refstr + ") and uitype='ref'";
                //get dataset relation obj
                DataSet ds = dataOperate.getDataset(conn, sql);
                if (ds != null && ds.Tables.Count > 0)
                {
                    DataTable dt = ds.Tables[0];
                    if (dt.Rows.Count > 0)
                    {
                        //rel ref exists
                        for (int k = 0; k < dt.Rows.Count; k++)
                        {
                            string vt = dt.Rows[k].ItemArray[0].ToString();
                             string vv = dt.Rows[k].ItemArray[1].ToString();
                            refset.Add(vt);//save current ref
                            if(!deepRef.ContainsKey(vt))
                                deepRef.Add(vt, vv);// save all ref

                             
                        }
                        if (refset.Count > 0)// get the ref successfully
                        {
                            //recursion get
                            getRef(conn, refset);
                        }

                    }

                }




            }
            else
            { 
                //no ref
            }
            return refset;
        }

以上就是C#遞歸應(yīng)用之實(shí)現(xiàn)JS文件的自動(dòng)引用的詳細(xì)內(nèi)容,更多關(guān)于C#遞歸實(shí)現(xiàn)JS文件引用的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • C#執(zhí)行外部命令的方法

    C#執(zhí)行外部命令的方法

    這篇文章主要介紹了C#執(zhí)行外部命令的方法,實(shí)例分析了C#調(diào)用CMD.exe程序執(zhí)行外部命令的技巧,需要的朋友可以參考下
    2015-06-06
  • C#結(jié)合JavaScript對(duì)Web控件進(jìn)行數(shù)據(jù)輸入驗(yàn)證的實(shí)現(xiàn)方法

    C#結(jié)合JavaScript對(duì)Web控件進(jìn)行數(shù)據(jù)輸入驗(yàn)證的實(shí)現(xiàn)方法

    在 Web 應(yīng)用的錄入界面,數(shù)據(jù)驗(yàn)證是一項(xiàng)重要的實(shí)現(xiàn)功能,數(shù)據(jù)驗(yàn)證是指確認(rèn) Web 控件輸入或選擇的數(shù)據(jù),本文我們將介紹如何通過(guò)C# 后端及JavaScript 前端對(duì) Web 控件進(jìn)行數(shù)據(jù)輸入有效性的驗(yàn)證,感興趣的朋友可以參考一下
    2024-05-05
  • C# OpenCvSharp實(shí)現(xiàn)去除字母后面的雜線

    C# OpenCvSharp實(shí)現(xiàn)去除字母后面的雜線

    這篇文章主要為大家詳細(xì)介紹了C#如何使用OpenCvSharp實(shí)現(xiàn)去除字母后面的雜線效果,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2023-11-11
  • C#獲取本地IP的四種方式示例詳解

    C#獲取本地IP的四種方式示例詳解

    這篇文章主要介紹了C#獲取本地IP的四種方式示例詳解, 文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-07-07
  • C#使用控制臺(tái)列出當(dāng)前所有可用的打印機(jī)列表

    C#使用控制臺(tái)列出當(dāng)前所有可用的打印機(jī)列表

    這篇文章主要介紹了C#使用控制臺(tái)列出當(dāng)前所有可用的打印機(jī)列表,涉及C#操作計(jì)算機(jī)硬件的相關(guān)使用技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2015-04-04
  • Unity游戲開發(fā)之2048游戲的實(shí)現(xiàn)

    Unity游戲開發(fā)之2048游戲的實(shí)現(xiàn)

    2048是一款數(shù)字益智游戲,初始數(shù)字則是由2+2組成的基數(shù)4。在操作方面的不同則表現(xiàn)為一步一格的移動(dòng),變成更為爽快的一次到底。相同數(shù)字的方?jīng)r在靠攏、相撞時(shí)會(huì)相加。本文將通過(guò)Unity3D實(shí)現(xiàn)這一游戲,需要的可以參考一下
    2022-03-03
  • WPF字體或內(nèi)容模糊的解決方法

    WPF字體或內(nèi)容模糊的解決方法

    WPF下開發(fā)的程序字體模糊,這個(gè)問(wèn)題或許大家都有遇到過(guò),為了解決WPF字體模糊,查閱了各種資料,結(jié)果偶然發(fā)現(xiàn)是自己疏忽了一些細(xì)節(jié)造成的,具體是什么細(xì)節(jié)呢,通過(guò)下面的這篇文章來(lái)一起看看吧,有需要的朋友們可以參考借鑒。
    2016-12-12
  • 深入理解C#中的枚舉

    深入理解C#中的枚舉

    本篇文章主要是對(duì)C#中的枚舉進(jìn)行了詳細(xì)的分析介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助
    2014-01-01
  • C# 清除cookies的代碼

    C# 清除cookies的代碼

    不同的瀏覽器會(huì)把cookie文件保存在不同的地方.這篇文章主要介紹了C# 清除cookies的代碼,需要的朋友可以參考下
    2016-10-10
  • C#中Invoke 和 BeginInvoke 的真正涵義

    C#中Invoke 和 BeginInvoke 的真正涵義

    這篇文章主要介紹了C#中Invoke 和 BeginInvoke 的真正涵義,需要的朋友可以參考下
    2014-10-10

最新評(píng)論

广昌县| 拜城县| 汶川县| 璧山县| 通山县| 五家渠市| 方山县| 抚宁县| 舟曲县| 三亚市| 禄丰县| 新郑市| 青河县| 六安市| 东山县| 瑞昌市| 武隆县| 巴林左旗| 泸西县| 濮阳市| 社会| 临清市| 黑河市| 山东省| 新化县| 碌曲县| 长武县| 台安县| 西平县| 伊金霍洛旗| 宜昌市| 民勤县| 廊坊市| 绵竹市| 新晃| 郁南县| 呼伦贝尔市| 安达市| 安多县| 临湘市| 商城县|