FrmWorkLogStats

This commit is contained in:
2020-06-16 01:48:50 +02:00
parent 2059053a03
commit ea5a8a8f8d
6 changed files with 334 additions and 30 deletions

View File

@@ -29,6 +29,7 @@
private void InitializeComponent()
{
this.splitWindow = new System.Windows.Forms.SplitContainer();
this.lblWorkLogTime = new System.Windows.Forms.Label();
this.btnExport = new System.Windows.Forms.Button();
this.btnImport = new System.Windows.Forms.Button();
this.cboImporters = new System.Windows.Forms.ComboBox();
@@ -39,6 +40,7 @@
this.btnPreviousDay = new System.Windows.Forms.Button();
this.dtToday = new System.Windows.Forms.DateTimePicker();
this.lsbWorkLog = new System.Windows.Forms.ListBox();
this.lblWorkLogItemTime = new System.Windows.Forms.Label();
this.btnRename = new System.Windows.Forms.Button();
this.dtEnd = new System.Windows.Forms.DateTimePicker();
this.dtStart = new System.Windows.Forms.DateTimePicker();
@@ -46,8 +48,7 @@
this.txtActivity = new System.Windows.Forms.TextBox();
this.btnDelete = new System.Windows.Forms.Button();
this.btnAdd = new System.Windows.Forms.Button();
this.lblWorkLogItemTime = new System.Windows.Forms.Label();
this.lblWorkLogTime = new System.Windows.Forms.Label();
this.btnStats = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.splitWindow)).BeginInit();
this.splitWindow.Panel1.SuspendLayout();
this.splitWindow.Panel2.SuspendLayout();
@@ -76,6 +77,7 @@
//
// splitWindow.Panel2
//
this.splitWindow.Panel2.Controls.Add(this.btnStats);
this.splitWindow.Panel2.Controls.Add(this.lblWorkLogItemTime);
this.splitWindow.Panel2.Controls.Add(this.btnRename);
this.splitWindow.Panel2.Controls.Add(this.dtEnd);
@@ -88,6 +90,17 @@
this.splitWindow.SplitterDistance = 442;
this.splitWindow.TabIndex = 0;
//
// lblWorkLogTime
//
this.lblWorkLogTime.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.lblWorkLogTime.Location = new System.Drawing.Point(193, 36);
this.lblWorkLogTime.Name = "lblWorkLogTime";
this.lblWorkLogTime.Size = new System.Drawing.Size(246, 21);
this.lblWorkLogTime.TabIndex = 9;
this.lblWorkLogTime.Text = "00:00:00";
this.lblWorkLogTime.TextAlign = System.Drawing.ContentAlignment.BottomRight;
//
// btnExport
//
this.btnExport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
@@ -198,6 +211,17 @@
this.lsbWorkLog.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.lsbWorkLog_DrawItem);
this.lsbWorkLog.SelectedIndexChanged += new System.EventHandler(this.lsbWorkLog_SelectedIndexChanged);
//
// lblWorkLogItemTime
//
this.lblWorkLogItemTime.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.lblWorkLogItemTime.Location = new System.Drawing.Point(136, 70);
this.lblWorkLogItemTime.Name = "lblWorkLogItemTime";
this.lblWorkLogItemTime.Size = new System.Drawing.Size(127, 20);
this.lblWorkLogItemTime.TabIndex = 7;
this.lblWorkLogItemTime.Text = "00:00:00";
this.lblWorkLogItemTime.TextAlign = System.Drawing.ContentAlignment.BottomRight;
//
// btnRename
//
this.btnRename.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
@@ -274,27 +298,15 @@
this.btnAdd.UseVisualStyleBackColor = true;
this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
//
// lblWorkLogItemTime
// btnStats
//
this.lblWorkLogItemTime.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.lblWorkLogItemTime.Location = new System.Drawing.Point(136, 70);
this.lblWorkLogItemTime.Name = "lblWorkLogItemTime";
this.lblWorkLogItemTime.Size = new System.Drawing.Size(127, 20);
this.lblWorkLogItemTime.TabIndex = 7;
this.lblWorkLogItemTime.Text = "00:00:00";
this.lblWorkLogItemTime.TextAlign = System.Drawing.ContentAlignment.BottomRight;
//
// lblWorkLogTime
//
this.lblWorkLogTime.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.lblWorkLogTime.Location = new System.Drawing.Point(193, 36);
this.lblWorkLogTime.Name = "lblWorkLogTime";
this.lblWorkLogTime.Size = new System.Drawing.Size(246, 21);
this.lblWorkLogTime.TabIndex = 9;
this.lblWorkLogTime.Text = "00:00:00";
this.lblWorkLogTime.TextAlign = System.Drawing.ContentAlignment.BottomRight;
this.btnStats.Location = new System.Drawing.Point(207, 31);
this.btnStats.Name = "btnStats";
this.btnStats.Size = new System.Drawing.Size(56, 22);
this.btnStats.TabIndex = 8;
this.btnStats.Text = "Stats";
this.btnStats.UseVisualStyleBackColor = true;
this.btnStats.Click += new System.EventHandler(this.btnStats_Click);
//
// FrmWorkLog
//
@@ -337,5 +349,6 @@
private System.Windows.Forms.Button btnRename;
private System.Windows.Forms.Label lblWorkLogItemTime;
private System.Windows.Forms.Label lblWorkLogTime;
private System.Windows.Forms.Button btnStats;
}
}

View File

@@ -235,6 +235,13 @@ namespace VAR.Toolbox.UI.Tools.WorkLog
WorkLog_Refresh();
}
private void btnStats_Click(object sender, EventArgs e)
{
if (_currentWorkLogItem == null) { return; }
FrmWorkLogStats frmStats = new FrmWorkLogStats { Activity = _currentWorkLogItem.Activity, WorkLog = _workLog };
frmStats.ShowDialog(this);
}
#endregion UI events
#region Private methods
@@ -383,6 +390,7 @@ namespace VAR.Toolbox.UI.Tools.WorkLog
btnAdd.Enabled = !enable;
btnDelete.Enabled = enable;
btnRename.Enabled = enable;
btnStats.Enabled = enable;
}
private void WorkLogItem_Update(bool refresh = true)
@@ -507,14 +515,6 @@ namespace VAR.Toolbox.UI.Tools.WorkLog
}
}
public class WorkLogItem
{
public DateTime DateStart { get; set; }
public DateTime DateEnd { get; set; }
public string Activity { get; set; }
public string Description { get; set; }
}
public class WorkLogConfig
{
public string LastName { get; set; }

View File

@@ -0,0 +1,165 @@
namespace VAR.Toolbox.UI.Tools.WorkLog
{
partial class FrmWorkLogStats
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.lsbDays = new System.Windows.Forms.ListBox();
this.lblDateStart = new System.Windows.Forms.Label();
this.txtActivity = new System.Windows.Forms.TextBox();
this.btnSearch = new System.Windows.Forms.Button();
this.btnClose = new System.Windows.Forms.Button();
this.lblDateEnd = new System.Windows.Forms.Label();
this.lblTotalTime = new System.Windows.Forms.Label();
this.dtpStart = new System.Windows.Forms.DateTimePicker();
this.dtpEnd = new System.Windows.Forms.DateTimePicker();
this.SuspendLayout();
//
// lsbDays
//
this.lsbDays.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.lsbDays.FormattingEnabled = true;
this.lsbDays.Location = new System.Drawing.Point(12, 113);
this.lsbDays.Name = "lsbDays";
this.lsbDays.Size = new System.Drawing.Size(393, 290);
this.lsbDays.TabIndex = 0;
//
// lblDateStart
//
this.lblDateStart.Location = new System.Drawing.Point(12, 87);
this.lblDateStart.Name = "lblDateStart";
this.lblDateStart.Size = new System.Drawing.Size(186, 23);
this.lblDateStart.TabIndex = 1;
this.lblDateStart.Text = "label1";
//
// txtActivity
//
this.txtActivity.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtActivity.Location = new System.Drawing.Point(12, 12);
this.txtActivity.Name = "txtActivity";
this.txtActivity.Size = new System.Drawing.Size(325, 20);
this.txtActivity.TabIndex = 2;
//
// btnSearch
//
this.btnSearch.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnSearch.Location = new System.Drawing.Point(343, 12);
this.btnSearch.Name = "btnSearch";
this.btnSearch.Size = new System.Drawing.Size(62, 20);
this.btnSearch.TabIndex = 3;
this.btnSearch.Text = "Search";
this.btnSearch.UseVisualStyleBackColor = true;
this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
//
// btnClose
//
this.btnClose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnClose.Location = new System.Drawing.Point(330, 413);
this.btnClose.Name = "btnClose";
this.btnClose.Size = new System.Drawing.Size(75, 23);
this.btnClose.TabIndex = 4;
this.btnClose.Text = "Close";
this.btnClose.UseVisualStyleBackColor = true;
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//
// lblDateEnd
//
this.lblDateEnd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.lblDateEnd.Location = new System.Drawing.Point(234, 87);
this.lblDateEnd.Name = "lblDateEnd";
this.lblDateEnd.Size = new System.Drawing.Size(171, 23);
this.lblDateEnd.TabIndex = 5;
this.lblDateEnd.Text = "label2";
this.lblDateEnd.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// lblTotalTime
//
this.lblTotalTime.AutoSize = true;
this.lblTotalTime.Location = new System.Drawing.Point(12, 406);
this.lblTotalTime.Name = "lblTotalTime";
this.lblTotalTime.Size = new System.Drawing.Size(35, 13);
this.lblTotalTime.TabIndex = 6;
this.lblTotalTime.Text = "label1";
//
// dtpStart
//
this.dtpStart.CustomFormat = "yyyy-MM-dd HH:mm:ss";
this.dtpStart.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
this.dtpStart.Location = new System.Drawing.Point(15, 38);
this.dtpStart.Name = "dtpStart";
this.dtpStart.Size = new System.Drawing.Size(141, 20);
this.dtpStart.TabIndex = 7;
//
// dtpEnd
//
this.dtpEnd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.dtpEnd.CustomFormat = "yyyy-MM-dd HH:mm:ss";
this.dtpEnd.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
this.dtpEnd.Location = new System.Drawing.Point(264, 38);
this.dtpEnd.Name = "dtpEnd";
this.dtpEnd.Size = new System.Drawing.Size(141, 20);
this.dtpEnd.TabIndex = 8;
//
// FrmWorkLogStats
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(417, 448);
this.Controls.Add(this.dtpEnd);
this.Controls.Add(this.dtpStart);
this.Controls.Add(this.lblTotalTime);
this.Controls.Add(this.lblDateEnd);
this.Controls.Add(this.btnClose);
this.Controls.Add(this.btnSearch);
this.Controls.Add(this.txtActivity);
this.Controls.Add(this.lblDateStart);
this.Controls.Add(this.lsbDays);
this.Name = "FrmWorkLogStats";
this.Text = "WorkLogStats";
this.Load += new System.EventHandler(this.FrmWorkLogStats_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.ListBox lsbDays;
private System.Windows.Forms.Label lblDateStart;
private System.Windows.Forms.TextBox txtActivity;
private System.Windows.Forms.Button btnSearch;
private System.Windows.Forms.Button btnClose;
private System.Windows.Forms.Label lblDateEnd;
private System.Windows.Forms.Label lblTotalTime;
private System.Windows.Forms.DateTimePicker dtpStart;
private System.Windows.Forms.DateTimePicker dtpEnd;
}
}

View File

@@ -0,0 +1,107 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace VAR.Toolbox.UI.Tools.WorkLog
{
public partial class FrmWorkLogStats : Form
{
public FrmWorkLogStats()
{
InitializeComponent();
}
public string Activity
{
get { return txtActivity.Text; }
set { txtActivity.Text = value; }
}
private List<WorkLogItem> _workLog = null;
public List<WorkLogItem> WorkLog
{
get { return _workLog; }
set { _workLog = value; }
}
private void FrmWorkLogStats_Load(object sender, EventArgs e)
{
dtpStart.Value = DateTime.Now.AddDays(-1);
dtpEnd.Value = DateTime.Now;
WorkLog_ProcessStats();
}
private void btnSearch_Click(object sender, EventArgs e)
{
WorkLog_ProcessStats();
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void WorkLog_ProcessStats()
{
bool found = false;
DateTime dateStart = DateTime.MaxValue;
DateTime dateEnd = DateTime.MinValue;
Dictionary<DateTime, TimeSpan> dictDaysHours = new Dictionary<DateTime, TimeSpan>();
foreach (WorkLogItem item in _workLog)
{
if (item.Activity.Contains(txtActivity.Text) == false) { continue; }
if (item.DateEnd < dtpStart.Value || item.DateStart > dtpEnd.Value) { continue; }
found = true;
if (item.DateStart < dateStart) { dateStart = item.DateStart; }
if (item.DateEnd > dateEnd) { dateEnd = item.DateEnd; }
DateTime dateItemDay = item.DateStart.Date;
TimeSpan tsItem = item.DateEnd - item.DateStart;
if (dictDaysHours.ContainsKey(dateItemDay))
{
TimeSpan tsDay = tsItem + dictDaysHours[dateItemDay];
dictDaysHours[dateItemDay] = tsDay;
}
else
{
dictDaysHours.Add(dateItemDay, tsItem);
}
}
if (found == false)
{
lblDateStart.Text = string.Empty;
lblDateEnd.Text = string.Empty;
lsbDays.Items.Clear();
lblTotalTime.Text = string.Empty;
return;
}
lblDateStart.Text = dateStart.ToString("yyyy-MM-dd HH:mm:ss");
lblDateEnd.Text = dateEnd.ToString("yyyy-MM-dd HH:mm:ss");
List<string> strDays = new List<string>();
DateTime dateDayStart = dateStart.Date;
DateTime dateDayEnd = dateEnd.Date;
DateTime dateDayCurrent = dateDayStart;
TimeSpan tsTotal = new TimeSpan(0);
do
{
if (dictDaysHours.ContainsKey(dateDayCurrent))
{
TimeSpan tsDay = dictDaysHours[dateDayCurrent];
strDays.Add(string.Format("{0} -- {1} h", dateDayCurrent.ToString("yyyy-MM-dd"), tsDay.ToString()));
tsTotal += tsDay;
}
dateDayCurrent = dateDayCurrent.AddDays(1);
} while (dateDayCurrent <= dateDayEnd);
lsbDays.Items.Clear();
lsbDays.Items.AddRange(strDays.ToArray());
lblTotalTime.Text = tsTotal.ToString();
}
}
}

View File

@@ -0,0 +1,12 @@
using System;
namespace VAR.Toolbox.UI.Tools.WorkLog
{
public class WorkLogItem
{
public DateTime DateStart { get; set; }
public DateTime DateEnd { get; set; }
public string Activity { get; set; }
public string Description { get; set; }
}
}

View File

@@ -226,9 +226,16 @@
<Compile Include="UI\Tools\PnlSuspension.Designer.cs">
<DependentUpon>PnlSuspension.cs</DependentUpon>
</Compile>
<Compile Include="UI\Tools\WorkLog\FrmWorkLogStats.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="UI\Tools\WorkLog\FrmWorkLogStats.Designer.cs">
<DependentUpon>FrmWorkLogStats.cs</DependentUpon>
</Compile>
<Compile Include="UI\Tools\WorkLog\IWorkLogImporter.cs" />
<Compile Include="UI\Tools\WorkLog\VARTextWorkLogImporter.cs" />
<Compile Include="UI\Tools\WorkLog\WorkLogImporterFactory.cs" />
<Compile Include="UI\Tools\WorkLog\WorkLogItem.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.manifest" />