TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
hthrkuh kuh
NA
3
1.5k
How to tick times from database in timer counts down remaini
Apr 20 2013 4:27 PM
How can I tick times from a database in timer (counts down remaining)?
I read time values from a database .
I organize the values in a table layout panel and I want the values to start ticking.
I tried this code, which works, but not exactly like I want:
using System
;
using System
.
Collections
.
Generic
;
using System
.
ComponentModel
;
using System
.
Data
;
using System
.
Drawing
;
using System
.
Linq
;
using System
.
Text
;
using System
.
Windows
.
Forms
;
namespace
mahsan
{
public
partial
class
marehet
:
Form
{
DataAccess da
= new
DataAccess
(
"db1"
);
DataTable dt
= new
DataTable
();
TableLayoutPanel tlp1
= new
TableLayoutPanel
();
RowStyle row
= new
RowStyle
();
DateTime remaining7
;
System
.
DateTime m_StopTime1
= default(
System
.
DateTime
);
System
.
DateTime m_StopTime
= default(
System
.
DateTime
);
DateTime
[]
myStrings
= new
DateTime
[
0
];
TimeSpan
[]
myStrings1
= new
TimeSpan
[
0
];
Label label777
= new
Label
();
Label label77
= new
Label
();
TimeSpan remaining1
=new
TimeSpan
();
Timer timer3
= new
Timer
();
public
marehet
()
{
InitializeComponent
();
tlp1
.
Size
= new
Size
(
400
,
200
);
tlp1
.
RightToLeft
=
RightToLeft
.
Yes
;
tlp1
.
AutoScroll
=
true
;
tlp1
.
CellBorderStyle
=
TableLayoutPanelCellBorderStyle
.
Inset
;
tlp1
.
Location
= new
System
.
Drawing
.
Point
(
400
,
0
);
tabPage5
.
Controls
.
Add
(
tlp1
);
dt
=
da
.
Quary
(
"select * from zman"
);
myStrings
= new
DateTime
[
dt
.
Rows
.
Count
];
myStrings1
= new
TimeSpan
[
dt
.
Rows
.
Count
];
for (
int i
=
0
;
i
<
dt
.
Rows
.
Count
;
i
++)
{
string gt
=
TableAccess
.
GetCell
(
dt
,
i
,
1
);
gt
=
gt
.
Substring
(
0
,
8
);
TimeSpan duration
=
TimeSpan
.
Parse
(
gt
);
myStrings1
[
i
] =
duration
;
}
timer1
.
Enabled
=
true
;
dt
=
da
.
Quary
(
"select * from zman"
);
for (
int k
=
0
;
k
<
dt
.
Rows
.
Count
;
k
++)
{
m_StopTime
= default(
System
.
DateTime
);
m_StopTime
=
DateTime
.
Now
.
Add
(
myStrings1
[
k
]);
myStrings
[
k
] =
m_StopTime
;
}
dt
=
da
.
Quary
(
"select * from zman"
);
for (
int i
=
0
;
i
<
dt
.
Rows
.
Count
;
i
++)
{
timer3
= new
Timer
();
timer3
.
Enabled
=
true
;
timer3
.
Interval
=
1000
;
timer3
.
Start
();
timer3
.
Tick
+= new
System
.
EventHandler
((
sender
,
e
) =>
timer3_Tick
(
sender
,
e
,
i
));
}
public
void timer3_Tick
(
object sender
,
EventArgs e
,
int li
)
{
if (
o
==
0
)
{
remaining1
= new
TimeSpan
();
}
remaining1
=
myStrings
[
li
].
Subtract
(
DateTime
.
Now
);
remaining1
= new
TimeSpan
(
remaining1
.
Hours
,
remaining1
.
Minutes
,
remaining1
.
Seconds
);
if (
o
==
0
)
{
label77
= new
Label
();
}
label77
.
Text
=
remaining1
.
ToString
();
label77
.
AutoSize
=
true
;
if (
remaining1
.
TotalSeconds
<
0
)
{
remaining1
=
TimeSpan
.
Zero
;
timer3
.
Enabled
=
false
;
}
if (
o
==
0
)
{
tlp1
.
Controls
.
Add
(
label77
,
1
,
li
);
}
o
++;
}
Reply
Answers (
0
)
MSSql server connection failed
How to Flush DNS Cache using .NET Inbuit Library Components