[控件学习-3]ComponentArt 的脚本注册机制学习
ComponentArt 的脚本注册判断还是很全面的,判断了各种情况,在控件开发学习中还是很值得借鉴的
一样画葫芦练手做了几个简单的控件:
All:SmartTip(改自ttyp的自动提示效果 ) ,自动提示
1.STextBox =>增加几个属性,只是为了拼Sql的时候字符转义方便些(TrimedText,SqlText,SqlTrimedText)
2.SButton = > 增加几个小属性,象confirm,waitmessage...
3.SImgButton = > 增加鼠标滑过,离开,按下的图片设置
4.SXpButton = > 按模板自动生成三组效果图片(鼠标滑过,离开,按下)
5.SGroupBox =>GroupBox 只有Caption属性,不过设计时写的不好(直接使用了系统的Designer).不直观,不过我自己够用了,改天有空再学习修改Designer
dll:/Files/walkingboy/LangZi.SmartSuite.Web.UI.WebControls.rar
注册代码源代码:
一样画葫芦练手做了几个简单的控件:
All:SmartTip(改自ttyp的自动提示效果 ) ,自动提示
1.STextBox =>增加几个属性,只是为了拼Sql的时候字符转义方便些(TrimedText,SqlText,SqlTrimedText)
2.SButton = > 增加几个小属性,象confirm,waitmessage...
3.SImgButton = > 增加鼠标滑过,离开,按下的图片设置
4.SXpButton = > 按模板自动生成三组效果图片(鼠标滑过,离开,按下)
5.SGroupBox =>GroupBox 只有Caption属性,不过设计时写的不好(直接使用了系统的Designer).不直观,不过我自己够用了,改天有空再学习修改Designer
dll:/Files/walkingboy/LangZi.SmartSuite.Web.UI.WebControls.rar
注册代码源代码:
  1
2 /// <summary>
      /// <summary>
3 /// 绘制全局脚本
      /// 绘制全局脚本
4 /// </summary>
      /// </summary>
5 /// <param name="output"></param>
      /// <param name="output"></param>
6 /// <param name="sDefaultPath"></param>
      /// <param name="sDefaultPath"></param>
7 /// <param name="sScriptFile"></param>
      /// <param name="sScriptFile"></param>
8 protected void WriteGlobalClientScript(HtmlTextWriter output, string sDefaultPath, string sScriptFile)
    protected void WriteGlobalClientScript(HtmlTextWriter output, string sDefaultPath, string sScriptFile)
9 {
    {
10 string sScript = GenerateClientScriptBlock(sDefaultPath, sScriptFile);
      string sScript = GenerateClientScriptBlock(sDefaultPath, sScriptFile);
11 string sInstanceId = sScriptFile;
          string sInstanceId = sScriptFile;
12
13 output.Write(sScript);
      output.Write(sScript);
14 }
    }
15
16
17 
    
18
19 /// <summary>
      /// <summary>
20 /// 获取脚本块
      /// 获取脚本块
21 /// </summary>
      /// </summary>
22 /// <param name="sDefaultPath"></param>
      /// <param name="sDefaultPath"></param>
23 /// <param name="sScriptFile"></param>
      /// <param name="sScriptFile"></param>
24 /// <returns></returns>
      /// <returns></returns>
25 private string GenerateClientScriptBlock(string sDefaultPath, string sScriptFile)
    private string GenerateClientScriptBlock(string sDefaultPath, string sScriptFile)
26 {
    {
27 string sScript = string.Empty;
      string sScript = string.Empty;
28 string sScriptLocation = string.Empty;
      string sScriptLocation = string.Empty;
29 //相应版本 主版本+副版本+编译版本
        //相应版本 主版本+副版本+编译版本
30 string sVersionString =
      string sVersionString =
31 Assembly.GetExecutingAssembly().GetName().Version.Major.ToString() + "_" +
        Assembly.GetExecutingAssembly().GetName().Version.Major.ToString() + "_" +
32 Assembly.GetExecutingAssembly().GetName().Version.Minor.ToString() + "_" +
        Assembly.GetExecutingAssembly().GetName().Version.Minor.ToString() + "_" +
33 Assembly.GetExecutingAssembly().GetName().Version.Build.ToString();
        Assembly.GetExecutingAssembly().GetName().Version.Build.ToString();
34 
        
35 if(this.ClientScriptLocation != string.Empty)//指定脚本位置
      if(this.ClientScriptLocation != string.Empty)//指定脚本位置
36 {
      {
37 sScriptLocation = Path.Combine(Path.Combine(this.ClientScriptLocation, sVersionString), sScriptFile).Replace("\\", "/");
        sScriptLocation = Path.Combine(Path.Combine(this.ClientScriptLocation, sVersionString), sScriptFile).Replace("\\", "/");
38 }
            }
39 else
      else
40 {
      {
41 // First, try application config variable
        // First, try application config variable
42 //首先,先从程序配置文件读取web.config
          //首先,先从程序配置文件读取web.config
43 string sLocation = ConfigurationSettings.AppSettings["ComponentArt.Web.UI.ClientScriptLocation"];
        string sLocation = ConfigurationSettings.AppSettings["ComponentArt.Web.UI.ClientScriptLocation"];
44 if(sLocation != null)
        if(sLocation != null)
45 {
        {
46 //脚本地址
            //脚本地址
47 sScriptLocation = Path.Combine(Path.Combine(sLocation, sVersionString), sScriptFile).Replace("\\", "/");
          sScriptLocation = Path.Combine(Path.Combine(sLocation, sVersionString), sScriptFile).Replace("\\", "/");
48 }
            }
49 
      
50 // Next, try server root
        // Next, try server root
51 //IIS根目录
          //IIS根目录
52 if(sScriptLocation == string.Empty)
        if(sScriptLocation == string.Empty)
53 {
        {
54 try
          try
55 {
          {
56 string sStandardRootClientScriptPath = Path.Combine(Path.Combine("/componentart_webui_client", sVersionString), sScriptFile).Replace("\\", "/");
            string sStandardRootClientScriptPath = Path.Combine(Path.Combine("/componentart_webui_client", sVersionString), sScriptFile).Replace("\\", "/");
57
58 if(File.Exists(Context.Server.MapPath(sStandardRootClientScriptPath)))
            if(File.Exists(Context.Server.MapPath(sStandardRootClientScriptPath)))
59 {
            {
60 sScriptLocation = sStandardRootClientScriptPath;
              sScriptLocation = sStandardRootClientScriptPath;
61 }
            }
62 }
          } 
63 catch {}
          catch {}
64 }
        }
65
66 // If failed, try application root
        // If failed, try application root
67 //程序根目录
          //程序根目录
68 if(sScriptLocation == string.Empty)
        if(sScriptLocation == string.Empty)
69 {
        {
70 try
          try
71 {
          {
72 string sAppRootClientScriptPath = Path.Combine(Path.Combine(Path.Combine(Page.Request.ApplicationPath, "componentart_webui_client"), sVersionString), sScriptFile).Replace("\\", "/");
            string sAppRootClientScriptPath = Path.Combine(Path.Combine(Path.Combine(Page.Request.ApplicationPath, "componentart_webui_client"), sVersionString), sScriptFile).Replace("\\", "/");
73
74 if(File.Exists(Context.Server.MapPath(sAppRootClientScriptPath)))
            if(File.Exists(Context.Server.MapPath(sAppRootClientScriptPath)))
75 {
            {
76 sScriptLocation = sAppRootClientScriptPath;
              sScriptLocation = sAppRootClientScriptPath;
77 }
            }
78 }
          } 
79 catch {}
          catch {}
80 }
        }
81 }
      }
82
83 if(sScriptLocation != string.Empty)
      if(sScriptLocation != string.Empty)
84 {
      {
85 // Do we have a tilde?
        // Do we have a tilde?
86 if(sScriptLocation.StartsWith("~") && Context != null && Context.Request != null)
        if(sScriptLocation.StartsWith("~") && Context != null && Context.Request != null)
87 {
        {
88 string sAppPath = Context.Request.ApplicationPath;
          string sAppPath = Context.Request.ApplicationPath;
89 if(sAppPath.EndsWith("/"))
          if(sAppPath.EndsWith("/"))
90 {
          {
91 sAppPath = sAppPath.Substring(0, sAppPath.Length - 1);
            sAppPath = sAppPath.Substring(0, sAppPath.Length - 1);
92 }
          }
93
94 sScriptLocation = sScriptLocation.Replace("~", sAppPath);
          sScriptLocation = sScriptLocation.Replace("~", sAppPath);
95 }
        }
96
97 //连接外部JS文件
          //连接外部JS文件
98 if(File.Exists(Context.Server.MapPath(sScriptLocation)))
        if(File.Exists(Context.Server.MapPath(sScriptLocation)))
99 {
        {
100 sScript = "<script src=\"" + sScriptLocation + "\" type=\"text/javascript\"></script>";
          sScript = "<script src=\"" + sScriptLocation + "\" type=\"text/javascript\"></script>";
101 }
        }
102 else
        else
103 {
        {
104 throw new Exception(sScriptLocation + " not found");
          throw new Exception(sScriptLocation + " not found");
105 }
        }
106 }
      }
107 else
      else 
108 {
      {
109 // If everything failed, emit our internal script
        // If everything failed, emit our internal script
110 //使用内嵌资源文件
          //使用内嵌资源文件
111 sScript = Utils.DemarcateClientScript(GetResourceContent(sDefaultPath + "." + sScriptFile));
        sScript = Utils.DemarcateClientScript(GetResourceContent(sDefaultPath + "." + sScriptFile));
112 }
      }
113
114 return sScript;
      return sScript;
115 }
    }

2
 /// <summary>
      /// <summary>3
 /// 绘制全局脚本
      /// 绘制全局脚本4
 /// </summary>
      /// </summary>5
 /// <param name="output"></param>
      /// <param name="output"></param>6
 /// <param name="sDefaultPath"></param>
      /// <param name="sDefaultPath"></param>7
 /// <param name="sScriptFile"></param>
      /// <param name="sScriptFile"></param>8
 protected void WriteGlobalClientScript(HtmlTextWriter output, string sDefaultPath, string sScriptFile)
    protected void WriteGlobalClientScript(HtmlTextWriter output, string sDefaultPath, string sScriptFile)9
 {
    {10
 string sScript = GenerateClientScriptBlock(sDefaultPath, sScriptFile);
      string sScript = GenerateClientScriptBlock(sDefaultPath, sScriptFile);11
 string sInstanceId = sScriptFile;
          string sInstanceId = sScriptFile;12

13
 output.Write(sScript);
      output.Write(sScript);14
 }
    }15

16

17
 
    18

19
 /// <summary>
      /// <summary>20
 /// 获取脚本块
      /// 获取脚本块21
 /// </summary>
      /// </summary>22
 /// <param name="sDefaultPath"></param>
      /// <param name="sDefaultPath"></param>23
 /// <param name="sScriptFile"></param>
      /// <param name="sScriptFile"></param>24
 /// <returns></returns>
      /// <returns></returns>25
 private string GenerateClientScriptBlock(string sDefaultPath, string sScriptFile)
    private string GenerateClientScriptBlock(string sDefaultPath, string sScriptFile)26
 {
    {27
 string sScript = string.Empty;
      string sScript = string.Empty;28
 string sScriptLocation = string.Empty;
      string sScriptLocation = string.Empty;29
 //相应版本 主版本+副版本+编译版本
        //相应版本 主版本+副版本+编译版本30
 string sVersionString =
      string sVersionString =31
 Assembly.GetExecutingAssembly().GetName().Version.Major.ToString() + "_" +
        Assembly.GetExecutingAssembly().GetName().Version.Major.ToString() + "_" +32
 Assembly.GetExecutingAssembly().GetName().Version.Minor.ToString() + "_" +
        Assembly.GetExecutingAssembly().GetName().Version.Minor.ToString() + "_" +33
 Assembly.GetExecutingAssembly().GetName().Version.Build.ToString();
        Assembly.GetExecutingAssembly().GetName().Version.Build.ToString();34
 
        35
 if(this.ClientScriptLocation != string.Empty)//指定脚本位置
      if(this.ClientScriptLocation != string.Empty)//指定脚本位置36
 {
      {37
 sScriptLocation = Path.Combine(Path.Combine(this.ClientScriptLocation, sVersionString), sScriptFile).Replace("\\", "/");
        sScriptLocation = Path.Combine(Path.Combine(this.ClientScriptLocation, sVersionString), sScriptFile).Replace("\\", "/");38
 }
            }39
 else
      else40
 {
      {41
 // First, try application config variable
        // First, try application config variable42
 //首先,先从程序配置文件读取web.config
          //首先,先从程序配置文件读取web.config43
 string sLocation = ConfigurationSettings.AppSettings["ComponentArt.Web.UI.ClientScriptLocation"];
        string sLocation = ConfigurationSettings.AppSettings["ComponentArt.Web.UI.ClientScriptLocation"];44
 if(sLocation != null)
        if(sLocation != null)45
 {
        {46
 //脚本地址
            //脚本地址47
 sScriptLocation = Path.Combine(Path.Combine(sLocation, sVersionString), sScriptFile).Replace("\\", "/");
          sScriptLocation = Path.Combine(Path.Combine(sLocation, sVersionString), sScriptFile).Replace("\\", "/");48
 }
            }49
 
      50
 // Next, try server root
        // Next, try server root51
 //IIS根目录
          //IIS根目录52
 if(sScriptLocation == string.Empty)
        if(sScriptLocation == string.Empty)53
 {
        {54
 try
          try55
 {
          {56
 string sStandardRootClientScriptPath = Path.Combine(Path.Combine("/componentart_webui_client", sVersionString), sScriptFile).Replace("\\", "/");
            string sStandardRootClientScriptPath = Path.Combine(Path.Combine("/componentart_webui_client", sVersionString), sScriptFile).Replace("\\", "/");57

58
 if(File.Exists(Context.Server.MapPath(sStandardRootClientScriptPath)))
            if(File.Exists(Context.Server.MapPath(sStandardRootClientScriptPath)))59
 {
            {60
 sScriptLocation = sStandardRootClientScriptPath;
              sScriptLocation = sStandardRootClientScriptPath;61
 }
            }62
 }
          } 63
 catch {}
          catch {}64
 }
        }65

66
 // If failed, try application root
        // If failed, try application root67
 //程序根目录
          //程序根目录68
 if(sScriptLocation == string.Empty)
        if(sScriptLocation == string.Empty)69
 {
        {70
 try
          try71
 {
          {72
 string sAppRootClientScriptPath = Path.Combine(Path.Combine(Path.Combine(Page.Request.ApplicationPath, "componentart_webui_client"), sVersionString), sScriptFile).Replace("\\", "/");
            string sAppRootClientScriptPath = Path.Combine(Path.Combine(Path.Combine(Page.Request.ApplicationPath, "componentart_webui_client"), sVersionString), sScriptFile).Replace("\\", "/");73

74
 if(File.Exists(Context.Server.MapPath(sAppRootClientScriptPath)))
            if(File.Exists(Context.Server.MapPath(sAppRootClientScriptPath)))75
 {
            {76
 sScriptLocation = sAppRootClientScriptPath;
              sScriptLocation = sAppRootClientScriptPath;77
 }
            }78
 }
          } 79
 catch {}
          catch {}80
 }
        }81
 }
      }82

83
 if(sScriptLocation != string.Empty)
      if(sScriptLocation != string.Empty)84
 {
      {85
 // Do we have a tilde?
        // Do we have a tilde?86
 if(sScriptLocation.StartsWith("~") && Context != null && Context.Request != null)
        if(sScriptLocation.StartsWith("~") && Context != null && Context.Request != null)87
 {
        {88
 string sAppPath = Context.Request.ApplicationPath;
          string sAppPath = Context.Request.ApplicationPath;89
 if(sAppPath.EndsWith("/"))
          if(sAppPath.EndsWith("/"))90
 {
          {91
 sAppPath = sAppPath.Substring(0, sAppPath.Length - 1);
            sAppPath = sAppPath.Substring(0, sAppPath.Length - 1);92
 }
          }93

94
 sScriptLocation = sScriptLocation.Replace("~", sAppPath);
          sScriptLocation = sScriptLocation.Replace("~", sAppPath);95
 }
        }96

97
 //连接外部JS文件
          //连接外部JS文件98
 if(File.Exists(Context.Server.MapPath(sScriptLocation)))
        if(File.Exists(Context.Server.MapPath(sScriptLocation)))99
 {
        {100
 sScript = "<script src=\"" + sScriptLocation + "\" type=\"text/javascript\"></script>";
          sScript = "<script src=\"" + sScriptLocation + "\" type=\"text/javascript\"></script>";101
 }
        }102
 else
        else103
 {
        {104
 throw new Exception(sScriptLocation + " not found");
          throw new Exception(sScriptLocation + " not found");105
 }
        }106
 }
      }107
 else
      else 108
 {
      {109
 // If everything failed, emit our internal script
        // If everything failed, emit our internal script110
 //使用内嵌资源文件
          //使用内嵌资源文件111
 sScript = Utils.DemarcateClientScript(GetResourceContent(sDefaultPath + "." + sScriptFile));
        sScript = Utils.DemarcateClientScript(GetResourceContent(sDefaultPath + "." + sScriptFile));112
 }
      }113

114
 return sScript;
      return sScript;115
 }
    } 
                    
                
 
      

 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号