| Name | Seconds | Duration |
| Customer1 call | 40 | 00:00:40 |
| customer2 call | 90640 | 25:10:40 |
| customer3 call | 1201 | 00:20:01 |
| customer4 call | 25 | 00:00:25 |
Below is the code...
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
SqlCommand slctVendors = new SqlCommand("SELECT TRUSTID as 'TRUSTS', COUNT(JOBIDST)as 'JOBS', " +
"CONVERT(char(8),DATEADD(second, sum(PLAYTIME),'00:00:00'), 108) " +
" as 'DURATION', SUM(PLAYTIME) " +
"FROM DCLIVEJOBS where PSTATUS < '95' GROUP BY TRUSTID", cn);
da.SelectCommand = slctVendors;
da.Fill(ds, "tblDclivejobs");
dgViewJobs.DataSource = ds.Tables["tblDclivejobs"];
int sum = 0;
for (int i = 0; i < dgViewJobs.Rows.Count; ++i)
{
sum += Convert.ToInt32(dgViewJobs.Rows[i].Cells[1].Value);
//sum += Convert.ToInt32(dgViewJobs.Rows[i].Cells[3].Value);
//count = Convert.ToInt32(dataGridView1.Rows[i].Cells[2].Value);
}
int sum1 = 0;
for (int j = 0; j < dgViewJobs.Rows.Count; ++j)
{
sum1 += Convert.ToInt32(dgViewJobs.Rows[j].Cells[3].Value);
//count = Convert.ToInt32(dataGridView1.Rows[i].Cells[2].Value);
}
int x = dgViewJobs.Rows.Count;
dgViewJobs.Rows[x - 1].Cells[0].Value = "Total".ToString();
dgViewJobs.Rows[x - 1].Cells[1].Value = label5.Text = sum.ToString();
dgViewJobs.Rows[x - 1].Cells[3].Value = label6.Text = sum1.ToString();
label5.Text = sum.ToString();
label6.Text = sum1.ToString();
int secs = Convert.ToInt32(label6.Text);
string du = string.Format("{0:00}:{1:00}:{2:00}",secs/3600,(secs/60)%60,secs%60);
label7.Text = du;
dgViewJobs.Rows[x - 1].Cells[2].Value = label7.Text;
cn.Close();
this.dgViewJobs.Columns[3].Visible = false;
dgViewJobs.ClearSelection();
foreach (DataGridViewColumn cl in dgViewJobs.Columns)
{
cl.SortMode = DataGridViewColumnSortMode.NotSortable;
}
ThomasPosted Feb 21, 2012, 10:51 AM
Just create a handler for the CellEndEdit event and put his ConvertToTime code in that event handler.
Jaiprakash SuryanathanPosted Jan 12, 2012, 3:55 AM
Satyapriya NayakPosted Jan 12, 2012, 2:49 AM
Try this...
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
MessageBox.Show(ConvertToTime(90640));
}
public string ConvertToTime(double timeSeconds)
{
int mySeconds = System.Convert.ToInt32(timeSeconds);
int myHours = mySeconds / 3600; //3600 Seconds in 1 hour
mySeconds %= 3600;
int myMinutes = mySeconds / 60; //60 Seconds in a minute
mySeconds %= 60;
string mySec = mySeconds.ToString(),
myMin = myMinutes.ToString(),
myHou = myHours.ToString();
if (myHours < 10) { myHou = myHou.Insert(0, "0"); }
if (myMinutes < 10) { myMin = myMin.Insert(0, "0"); }
if (mySeconds < 10) { mySec = mySec.Insert(0, "0"); }
return myHou + ":" + myMin + ":" + mySec;
}
}
}
Thanks