0
Reply

How to tick times from database in timer counts down remaini

hthrkuh kuh

hthrkuh kuh

Apr 20 2013 4:27 PM
1.2k
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(4000);
 
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 0dt.Rows.Counti++)
 {
 
 
string gt TableAccess.GetCell(dti1);
 
gt gt.Substring(08);
 
TimeSpan duration TimeSpan.Parse(gt);

 
myStrings1[i] = duration;


 }



 
timer1.Enabled true;

 
dt da.Quary("select * from zman");
 for (
int k=0kdt.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 0dt.Rows.Counti++)
 { 


 
timer3 = new Timer();
 
timer3.Enabled true;
 
timer3.Interval 1000;
 
timer3.Start();

 
timer3.Tick += new System.EventHandler((sendere) => timer3_Tick(senderei));

 }
 
public 
void timer3_Tick(object senderEventArgs eint li)
 {

          if (== 0)
 {
 
remaining1 = new TimeSpan();
 }
       remaining1 myStrings[li].Subtract(DateTime.Now);
 
 
remaining1 = new TimeSpan(remaining1.Hoursremaining1.Minutesremaining1.Seconds);
         

 
if (== 0)
 {
 
label77 = new Label(); 
 }
 
label77.Text remaining1.ToString();
 
label77.AutoSize true;
         

 
if (remaining1.TotalSeconds 0)
 {
 
remaining1 TimeSpan.Zero;
             

 
timer3.Enabled false;
 }
 

 
if (== 0)
 {


 
tlp1.Controls.Add(label771li);
 }
 
 
o++;
 
 }