/// <summary> /// Отобразить рабочие промежутки /// </summary> private void ShowTimes() { int selectNumber = TimesList.CurrentRow != null ? TimesList.CurrentRow.Index : 0; m_TimesInfos = m_DatabaseTools.GetTimesRows(m_ProjectInfo.ID); TimesList.Rows.Clear(); labelInfo.Text = ""; foreach (Exchange.TimesInfo timeInfo in m_TimesInfos) { var param = new object[] { timeInfo.DateStart.ToString(), timeInfo.DateStop != null?timeInfo.DateStop.ToString() : "" }; TimesList.Rows.Add(param); } TimesList.Focus(); if (TimesList.Rows.Count > 0) { if (selectNumber < TimesList.Rows.Count) { TimesList.Rows[selectNumber].Cells[0].Selected = true; } else { TimesList.Rows[TimesList.Rows.Count - 1].Cells[0].Selected = true; } } Color col = Color.FromArgb(255, 240, 240, 240); for (int i = 0; i < TimesList.Rows.Count; i += 2) { TimesList.Rows[i].DefaultCellStyle.BackColor = col; } if (m_TimesInfos.Length > 0 && m_TimesInfos[m_TimesInfos.Length - 1].DateStop == null) { buttonStart.Enabled = false; buttonStop.Enabled = true; timerWork.Enabled = true; } else { buttonStart.Enabled = true; buttonStop.Enabled = false; timerWork.Enabled = false; } var timesTools = new TimeTools(); labelInfo.Text = "Общее время работы над проектом: " + timesTools.GetTimeFromSecond(GetAllSeconds(null)); }
/// <summary> /// Получить суммарное количество секунд, потраченное на проект /// </summary> /// <param name="rowIndex">Выделенный номер в списке времён</param> /// <returns></returns> private long GetAllSeconds(int?rowIndex) { var timesTools = new TimeTools(); long allSec = 0; if (rowIndex == null) { foreach (Exchange.TimesInfo timeInfo in m_TimesInfos) { DateTime stopTime = timeInfo.DateStop.HasValue ? timeInfo.DateStop.Value : DateTime.Now; allSec += timesTools.GetSeconds(timeInfo.DateStart, stopTime); } } else { DateTime stopTime = m_TimesInfos[rowIndex.Value].DateStop.HasValue ? m_TimesInfos[rowIndex.Value].DateStop.Value : DateTime.Now; allSec += timesTools.GetSeconds(m_TimesInfos[rowIndex.Value].DateStart, stopTime); } return(allSec); }
/// <summary> /// Изменение времени работы /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void timerWork_Tick(object sender, EventArgs e) { var timesTools = new TimeTools(); labelInfo.Text = "Общее время работы над проектом: " + timesTools.GetTimeFromSecond(GetAllSeconds(null)); }