@@ -17,36 +17,32 @@ public partial class controls_ctrlTimerLabel : System.Web.UI.UserControl
1717 private string CurrentState ;
1818 private int TimeInState ;
1919 TimeSpan span ;
20- string time ;
20+ string sValue ;
2121
2222 protected void Page_Load ( object sender , EventArgs e )
2323 {
2424 ObjectName = screenObject . Property ( "Object Name" ) . Value ;
25- OSAEObject timerObj = OSAEObjectManager . GetObjectByName ( ObjectName ) ;
26- if ( timerObj . Property ( "OFF TIMER" ) . Value != "" )
27- OffTimer = Int32 . Parse ( timerObj . Property ( "OFF TIMER" ) . Value ) ;
28- else
29- OffTimer = 0 ;
30- CurrentState = timerObj . State . Value ;
31-
32- TimeSpan ts = DateTime . Now - DateTime . Parse ( timerObj . LastUpd ) ;
33- TimeInState = ( int ) ts . TotalSeconds ;
25+ OSAEObjectState os = OSAEObjectStateManager . GetObjectStateValue ( ObjectName ) ;
26+ CurrentState = os . Value ;
3427
35- if ( CurrentState == "OFF" )
36- time = "OFF" ;
37- else
38- {
39- span = TimeSpan . FromSeconds ( OffTimer - TimeInState ) ;
40- time = span . ToString ( @"mm\:ss" ) ;
41- }
28+ OffTimer = Convert . ToUInt16 ( OSAEObjectPropertyManager . GetObjectPropertyValue ( ObjectName , "OFF TIMER" ) . Value ) ;
29+ TimeInState = ( int ) os . TimeInState ;
4230
4331 string sBackColor = screenObject . Property ( "Back Color" ) . Value ;
4432 string sForeColor = screenObject . Property ( "Fore Color" ) . Value ;
4533 string sPrefix = screenObject . Property ( "Prefix" ) . Value ;
4634 string sSuffix = screenObject . Property ( "Suffix" ) . Value ;
4735 string iFontSize = screenObject . Property ( "Font Size" ) . Value ;
4836
49- TimerLabel . Text = time ;
37+ if ( CurrentState == "OFF" )
38+ sValue = os . StateLabel ;
39+ else
40+ {
41+ span = TimeSpan . FromSeconds ( OffTimer - TimeInState ) ; //Or TimeSpan.FromSeconds(seconds); (see Jakob C´s answer)
42+ sValue = span . ToString ( @"mm\:ss" ) ;
43+ }
44+
45+ TimerLabel . Text = sValue ;
5046 TimerLabel . Attributes . Add ( "Style" , "position:absolute;top:" + ( Int32 . Parse ( screenObject . Property ( "Y" ) . Value ) + 50 ) . ToString ( ) + "px;left:" + ( Int32 . Parse ( screenObject . Property ( "X" ) . Value ) + 10 ) . ToString ( ) + "px;z-index:" + ( Int32 . Parse ( screenObject . Property ( "ZOrder" ) . Value ) + 10 ) . ToString ( ) + ";" ) ;
5147
5248 if ( sBackColor != "" )
0 commit comments