Power by DMForum.NET!
RSS | ATOM | WAP
DMForum.NET 官方支持讨论区 > 交流区 > 项目交流

浏览主题:sdfsdf

主题:sdfsdf
8899
普通会员
1级
等级:新手上路
发帖:3
金钱:39
经验:43
性别:保密
状态:离线
注册:2006-12-23 15:01:00
sdfsdf  
[ 2006-12-23 15:44:34 ]
查看此内容需要的条件
属于下列团队的用户:
普通会员
论坛版主
分区版主
实际内容:
你暂时未达到查看条件

testboy1
普通会员
1级
等级:新手上路
发帖:4
金钱:47
经验:44
性别:保密
状态:离线
注册:2006-12-23 14:01:00
RE:sdfsdf  
[ 2006-12-24 22:19:10 ]
c# 程序代码
  1 
  2 namespace DControls
  3 {
  4     using System;
  5     using System.Data;
  6     using System.Drawing;
  7     using System.Web;
  8     using System.Web.UI;
  9     using System.Text;
 10     using System.Collections.Specialized;
 11     using System.Web.UI.WebControls;
 12     using System.Web.UI.HtmlControls;
 13     
 14     /// <summary>
 15     /// Web based timer control created by Deepson Thomas.
 16     /// For any help or comments just shoot a mail to deepson@gmail.com 
 17     /// </summary>
 18     public class Timer : System.Web.UI.UserControl, IPostBackDataHandler
 19     {
 20         #region Private Variables 
 21         private int prIntInterval;
 22         private IntervalMode prIntervalMode = IntervalMode.Minutes;
 23         private TimerAction prTimerAction = TimerAction.Postback_Page;
 24         private string prJSFunctionName = "";
 25         private bool _Enabled = false;
 26         #endregion 
 27 
 28         protected System.Web.UI.HtmlControls.HtmlInputHidden HIDTimer; 
 29 
 30         #region Enumerations 
 31         public enum TimerAction
 32         {
 33             Postback_Page,
 34             Execute_JSFunction
 35         };
 36         
 37         public enum IntervalMode
 38         {
 39             Milliseconds,
 40             Seconds,
 41             Minutes
 42         };
 43         #endregion 
 44         
 45         #region Public Properties 
 46 
 47         #region IsPostedBackByTimer 
 48         /// <summary>
 49         /// Returns true if the parent page is posted back by timer
 50         /// </summary>
 51         public bool IsPostedBackByTimer
 52         {
 53             get
 54             {
 55                 bool IsSubmitedByTimer;
 56                 if(HIDTimer.Value.Trim() == "1")
 57                 {
 58                     IsSubmitedByTimer = true;
 59                 }
 60                 else if(HIDTimer.Value.Trim() == "0")
 61                 {
 62                     IsSubmitedByTimer = false;
 63                 }
 64                 else
 65                 {
 66                     IsSubmitedByTimer = false;
 67                 }
 68 
 69                 return IsSubmitedByTimer;
 70             }
 71         }
 72         #endregion
 73 
 74         #region SetJSFunctionName 
 75         /// <summary>
 76         /// Gets or sets the javascript method name if the timer action is executing a clientside method
 77         /// </summary>
 78         public string SetJSFunctionName
 79         {
 80             get
 81             {
 82                 return prJSFunctionName;
 83             }
 84 
 85             set
 86             {
 87                 prJSFunctionName = value;
 88             }
 89         }
 90         #endregion
 91 
 92         #region SetTimerAction 
 93         /// <summary>
 94         /// Gets or Sets the action type need to be performed by the timer. Default is page postback
 95         /// </summary>
 96         public TimerAction SetTimerAction
 97         {
 98             get
 99             {
100                 return prTimerAction;
101             }
102 
103             set
104             {
105                 prTimerAction = value;
106             }
107 
108         }
109         #endregion
110 
111         #region SetIntervalMode 
112         /// <summary>
113         /// Inform the timer that the passed interval is in milliseconds or seconds or in minutes. Default is minutes
114         /// </summary>
115         public IntervalMode SetIntervalMode
116         {
117             get
118             {
119                 return prIntervalMode;
120             }
121 
122             set
123             {
124                 prIntervalMode = value;
125             }
126 
127         }
128         #endregion
129  
130         #region Interval 
131         /// <summary>
132         /// The frequency of timer execution interval in milliseconds 
133         /// </summary>
134         public int Interval
135         {
136             get
137             {
138                 return prIntInterval; 
139             }
140 
141             set
142             {
143                 prIntInterval = value;
144             }
145         } 
146         #endregion 
147 
148         #region Enabled 
149         /// <summary>
150         /// Gets or sets whether the timer is enabled or disabled. Default is false
151         /// </summary>
152         public bool Enabled
153         {
154             get
155             {
156                 return _Enabled;
157             }
158 
159             set
160             {
161                 _Enabled = value;
162             }
163         }
164         #endregion
165 
166         #endregion
167         
168         #region Page Load Event 
169         private void Page_Load(object sender, System.EventArgs e)
170         {
171             #region Converting whatever the data comes to milliseconds 
172             if(prIntervalMode == IntervalMode.Seconds)
173             {
174                 prIntInterval = prIntInterval*1000;
175             }
176             else if(prIntervalMode == IntervalMode.Minutes)
177             {
178                 prIntInterval = ((prIntInterval*60)*1000);
179             }
180             #endregion
181             
182             if(prIntInterval < 500)
183             {
184                 throw new Exception("Invalid timer interval. Give a minimum of 500 milliseconds.");
185             }
186             
187             Page.RegisterRequiresPostBack(this);
188             
189             if(_Enabled) // Create JSscript only if timer is enabled 
190             {
191                 if (Page != null)
192                 {
193                     #region Creating & Registering Clientside Timer Script 
194                     HIDTimer.Value = "0"//Set the initial value for the hidden field 
195 
196                     if(!Page.IsStartupScriptRegistered(this.ID+"_DControl"))
197                     {
198                         StringBuilder sbClientJS = new StringBuilder();
199 
200                         if(prTimerAction == TimerAction.Postback_Page)
201                         {
202                             sbClientJS.Append("\n<script language='javascript'>\n");
203                             sbClientJS.Append("{\n");
204                             sbClientJS.Append("window.setTimeout(\"document.forms(0)."+ this.ID.ToString() +"_HIDTimer.value='1';"+Page.GetPostBackClientEvent(this,"")+"\","+ prIntInterval.ToString() +");\n");
205                             sbClientJS.Append("}\n");
206                             sbClientJS.Append("</script>\n");
207                             Page.RegisterStartupScript(this.ID+"_DControl", sbClientJS.ToString());
208                         }
209                         else if(prTimerAction == TimerAction.Execute_JSFunction)
210                         {
211                             if(prJSFunctionName.Trim().Length <= 2)
212                             {
213                                 throw new Exception("Javascript method name not passed");
214                             }
215                             else
216                             {
217                                 HIDTimer.Visible = false// No need to send the hidden field if no postback is required 
218                                 sbClientJS.Append("\n<script language='javascript'>\n"); 
219                                 sbClientJS.Append("webTimer();\n"); 
220                                 sbClientJS.Append("function webTimer()\n"); 
221                                 sbClientJS.Append("{\n"); 
222                                 sbClientJS.Append("\ttry\n\t{\n\t\twindow.setTimeout(\""+ prJSFunctionName.ToString().Trim() +";webTimer()\","+ prIntInterval.ToString() +");\n\t}catch(e){}\n"); 
223                                 sbClientJS.Append("}\n"); 
224                                 sbClientJS.Append("</script>\n"); 
225                                 Page.RegisterStartupScript(this.ID+"_DControl", sbClientJS.ToString()); 
226                             }
227                         }
228                     }
229                     #endregion
230                 }
231             }
232         }
233         #endregion
234 
235         #region Web Form Designer generated code
236         override protected void OnInit(EventArgs e)
237         {
238             //
239             // CODEGEN: This call is required by the ASP.NET Web Form Designer.
240             //
241             InitializeComponent();
242             base.OnInit(e);
243         }
244         
245         /// <summary>
246         ///        Required method for Designer support - do not modify
247         ///        the contents of this method with the code editor.
248         /// </summary>
249         private void InitializeComponent()
250         {
251             this.Load += new System.EventHandler(this.Page_Load);
252 
253         }
254         #endregion
255 
256         #region Implementing IPostBackDataHandler Interface 
257         /// <summary>
258         /// Process incoming form data and update properties accordingly,
259         /// </summary>
260         /// <param name="postDataKey">String</param>
261         /// <param name="postCollection">NameValueCollection</param>
262         /// <returns></returns>
263         bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection)
264         {
265             if(postDataKey==this.ID)
266             {
267                 return true;
268             }
269             else
270             {
271                 return false;
272             }
273         }
274         
275         void IPostBackDataHandler.RaisePostDataChangedEvent() { }
276         #endregion
277 
278     }
279 }
280 
281 
testboy1
普通会员
1级
等级:新手上路
发帖:4
金钱:47
经验:44
性别:保密
状态:离线
注册:2006-12-23 14:01:00
RE:sdfsdf  
[ 2006-12-24 22:20:27 ]
vb 程序代码
 1 
 2 Imports Microsoft.VisualBasic
 3 Imports System.Web
 4 Namespace Forum.Model
 5     Public Class VBCache
 6         Public ReloadTimeType, CacheName As String
 7         Private TDate As Date
 8         Private LocalCacheName As String
 9 
10         Public WriteOnly Property Reloadtime() As Integer
11             Set(ByVal TValue As Integer)
12 
13                 Select Case LCase(ReloadTimeType)
14                     Case "d"
15                         TDate = DateTime.Now.AddDays(TValue)
16                     Case "h"
17                         TDate = DateTime.Now.AddHours(TValue)
18                     Case "m"
19                         TDate = DateTime.Now.AddMinutes(TValue)
20                     Case "s"
21                         TDate = DateTime.Now.AddSeconds(TValue)
22                     Case Else
23                         TDate = DateTime.Now.AddSeconds(TValue)
24                 End Select
25             End Set
26         End Property
27         Public WriteOnly Property Name() As String
28             Set(ByVal TValue As String)
29                 LocalCacheName = LCase(TValue)
30             End Set
31         End Property
32 
33         Public Property Value() As Object
34             Get
35                 Return HttpContext.Current.Cache(CacheName & "_" & LocalCacheName)
36             End Get
37             Set(ByVal TValue As Object)
38                 SetCache(TValue)
39             End Set
40         End Property
41         Public Sub New()
42 
43             ReloadTimeType = "s"
44             Reloadtime = 30
45             CacheName = "WYD"
46         End Sub
47         Private Sub SetCache(ByVal NewValue As Object)
48             HttpContext.Current.Cache.Insert(CacheName & "_" & LocalCacheName, NewValue, Nothing, TDate, TimeSpan.Zero)
49         End Sub
50 
51         Public Function IsEmpty() As Boolean
52             If HttpContext.Current.Cache(CacheName & "_" & LocalCacheName) Is Nothing Then
53                 Return True
54             Else
55                 Return False
56             End If
57         End Function
58         Public Sub DelCache(ByVal TName As String)
59             HttpContext.Current.Cache.Remove(CacheName & "_" & LCase(TName))
60         End Sub
61     End Class
62 End Namespace
63 
64 
65 

回到顶部
Powered by DMForum.NET  1.4 Beta . URIMAP enabled. DEBUG enabled.
Copyright © 2003-2006 Devms.Com. All rights reserved.