akshay rasalakar

akshay rasalakar

  • 1.5k
  • 128
  • 8.9k

Time calculation

Feb 18 2015 8:36 AM
I have mentioned my problem below  
st = "UPDATE tbl_time set time_out='" + dt1.ToString("hh:mm:ss") + "' WHERE ID=(SELECT MAX(ID) FROM tbl_time)";
db.ExeQuery(st);
st = "Select * from tbl_time where ID=(Select MAX(ID) from tbl_time)";
dr = db.readall(st);
if (dr.Read() == true)
{
txt1.Text = dr["time_in"].ToString();
txt2.Text = dr["time_out"].ToString();
}
TimeSpan t1 = TimeSpan.Parse(txt1.Text);
TimeSpan t2 = TimeSpan.Parse(txt2.Text);
TimeSpan ts = t2 - t1;
dr.Close();
st = "UPDATE tbl_time set tot='" + ts + "' WHERE ID=(SELECT MAX(ID) FROM tbl_time)";
db.ExeQuery(st);
st = "Select * from tbl_time where ID=(Select MAX(ID) from tbl_time)";
dr = db.readall(st);
if (dr.Read() == true)
{
txt3.Text = dr["tot"].ToString();
}
dr.Close();
TimeSpan t3 = TimeSpan.Parse(txt3.Text);
double fee = 0;
 
 // In ts variable i'm storing the start and end time i.e total time
if (ts.TotalMinutes < 60)   // Here is my doubt If the user spend time less than 60 min i want make charge of  10Rs i.e i have done 
{                                        //but if the user spend 120 min i want make charge of 20Rs, but in the database it saving like 60rs.
   // I'm not getting where my calculation is wrong   
st = "UPDATE tbl_time set amt='" + fee + "' WHERE ID=(SELECT MAX(ID) FROM tbl_time)";
db.ExeQuery(st);
}
if (ts.TotalMilliseconds > 60)
{
fee = (ts.TotalMinutes / 10) * 10;
st = "UPDATE tbl_time set amt='" + fee + "' WHERE ID=(SELECT MAX(ID) FROM tbl_time)";
db.ExeQuery(st);
}
}
}

Answers (2)