FrmWorkLogSumary: Form to sumarice a date range.

This commit is contained in:
2020-07-08 00:55:34 +02:00
parent 2fe83f1202
commit 6d80a5d553
6 changed files with 479 additions and 11 deletions

View File

@@ -40,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.btnSearch = new System.Windows.Forms.Button();
this.btnStats = new System.Windows.Forms.Button();
this.lblWorkLogItemTime = new System.Windows.Forms.Label();
this.btnRename = new System.Windows.Forms.Button();
@@ -49,7 +50,7 @@
this.txtActivity = new System.Windows.Forms.TextBox();
this.btnDelete = new System.Windows.Forms.Button();
this.btnAdd = new System.Windows.Forms.Button();
this.btnSearch = new System.Windows.Forms.Button();
this.btnSumary = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.splitWindow)).BeginInit();
this.splitWindow.Panel1.SuspendLayout();
this.splitWindow.Panel2.SuspendLayout();
@@ -64,6 +65,7 @@
//
// splitWindow.Panel1
//
this.splitWindow.Panel1.Controls.Add(this.btnSumary);
this.splitWindow.Panel1.Controls.Add(this.lblWorkLogTime);
this.splitWindow.Panel1.Controls.Add(this.btnExport);
this.splitWindow.Panel1.Controls.Add(this.btnImport);
@@ -96,9 +98,9 @@
//
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.Location = new System.Drawing.Point(273, 36);
this.lblWorkLogTime.Name = "lblWorkLogTime";
this.lblWorkLogTime.Size = new System.Drawing.Size(246, 21);
this.lblWorkLogTime.Size = new System.Drawing.Size(166, 21);
this.lblWorkLogTime.TabIndex = 9;
this.lblWorkLogTime.Text = "00:00:00";
this.lblWorkLogTime.TextAlign = System.Drawing.ContentAlignment.BottomRight;
@@ -213,6 +215,16 @@
this.lsbWorkLog.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.lsbWorkLog_DrawItem);
this.lsbWorkLog.SelectedIndexChanged += new System.EventHandler(this.lsbWorkLog_SelectedIndexChanged);
//
// btnSearch
//
this.btnSearch.Location = new System.Drawing.Point(68, 119);
this.btnSearch.Name = "btnSearch";
this.btnSearch.Size = new System.Drawing.Size(75, 23);
this.btnSearch.TabIndex = 9;
this.btnSearch.Text = "Search";
this.btnSearch.UseVisualStyleBackColor = true;
this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
//
// btnStats
//
this.btnStats.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
@@ -310,15 +322,15 @@
this.btnAdd.UseVisualStyleBackColor = true;
this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
//
// btnSearch
// btnSumary
//
this.btnSearch.Location = new System.Drawing.Point(68, 119);
this.btnSearch.Name = "btnSearch";
this.btnSearch.Size = new System.Drawing.Size(75, 23);
this.btnSearch.TabIndex = 9;
this.btnSearch.Text = "Search";
this.btnSearch.UseVisualStyleBackColor = true;
this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
this.btnSumary.Location = new System.Drawing.Point(194, 34);
this.btnSumary.Name = "btnSumary";
this.btnSumary.Size = new System.Drawing.Size(73, 23);
this.btnSumary.TabIndex = 10;
this.btnSumary.Text = "Sumary";
this.btnSumary.UseVisualStyleBackColor = true;
this.btnSumary.Click += new System.EventHandler(this.btnSumary_Click);
//
// FrmWorkLog
//
@@ -363,5 +375,6 @@
private System.Windows.Forms.Label lblWorkLogTime;
private System.Windows.Forms.Button btnStats;
private System.Windows.Forms.Button btnSearch;
private System.Windows.Forms.Button btnSumary;
}
}

View File

@@ -242,6 +242,12 @@ namespace VAR.Toolbox.UI.Tools.WorkLog
FrmWorkLogStats frmStats = new FrmWorkLogStats { Activity = _currentWorkLogItem.Activity, WorkLog = _workLog };
frmStats.ShowDialog(this);
}
private void btnSumary_Click(object sender, EventArgs e)
{
FrmWorkLogSumary frmStats = new FrmWorkLogSumary { WorkLog = _workLog };
frmStats.ShowDialog(this);
}
private void btnSearch_Click(object sender, EventArgs e)
{
if (_workLog == null) { return; }

View File

@@ -0,0 +1,182 @@
namespace VAR.Toolbox.UI.Tools.WorkLog
{
partial class FrmWorkLogSumary
{
/// <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.lsbActivities = new System.Windows.Forms.ListBox();
this.lblDateStart = new System.Windows.Forms.Label();
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.chkOnlyGroups = new System.Windows.Forms.CheckBox();
this.txtActivity = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// lsbActivities
//
this.lsbActivities.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.lsbActivities.FormattingEnabled = true;
this.lsbActivities.Location = new System.Drawing.Point(12, 113);
this.lsbActivities.Name = "lsbActivities";
this.lsbActivities.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;
this.lsbActivities.Size = new System.Drawing.Size(393, 290);
this.lsbActivities.TabIndex = 0;
this.lsbActivities.SelectedIndexChanged += new System.EventHandler(this.lsbActivities_SelectedIndexChanged);
this.lsbActivities.KeyDown += new System.Windows.Forms.KeyEventHandler(this.lsbActivities_KeyDown);
//
// 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";
//
// 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.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
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;
//
// chkOnlyGroups
//
this.chkOnlyGroups.AutoSize = true;
this.chkOnlyGroups.Location = new System.Drawing.Point(15, 64);
this.chkOnlyGroups.Name = "chkOnlyGroups";
this.chkOnlyGroups.Size = new System.Drawing.Size(81, 17);
this.chkOnlyGroups.TabIndex = 9;
this.chkOnlyGroups.Text = "OnlyGroups";
this.chkOnlyGroups.UseVisualStyleBackColor = true;
//
// txtActivity
//
this.txtActivity.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtActivity.Location = new System.Drawing.Point(12, 422);
this.txtActivity.Name = "txtActivity";
this.txtActivity.Size = new System.Drawing.Size(312, 20);
this.txtActivity.TabIndex = 10;
//
// FrmWorkLogSumary
//
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.txtActivity);
this.Controls.Add(this.chkOnlyGroups);
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.lblDateStart);
this.Controls.Add(this.lsbActivities);
this.Name = "FrmWorkLogSumary";
this.Text = "WorkLogSumary";
this.Load += new System.EventHandler(this.FrmWorkLogStats_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.ListBox lsbActivities;
private System.Windows.Forms.Label lblDateStart;
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;
private System.Windows.Forms.CheckBox chkOnlyGroups;
private System.Windows.Forms.TextBox txtActivity;
}
}

View File

@@ -0,0 +1,136 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace VAR.Toolbox.UI.Tools.WorkLog
{
public partial class FrmWorkLogSumary : Form
{
public FrmWorkLogSumary()
{
InitializeComponent();
}
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.Date;
dtpEnd.Value = DateTime.Now.Date.AddDays(1).AddSeconds(-1);
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<string, TimeSpan> dictActivityHours = new Dictionary<string, TimeSpan>();
foreach (WorkLogItem item in _workLog)
{
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; }
TimeSpan tsItem = item.DateEnd - item.DateStart;
if (dictActivityHours.ContainsKey(item.Activity))
{
TimeSpan tsDay = tsItem + dictActivityHours[item.Activity];
dictActivityHours[item.Activity] = tsDay;
}
else
{
dictActivityHours.Add(item.Activity, tsItem);
}
}
if (found == false)
{
lblDateStart.Text = string.Empty;
lblDateEnd.Text = string.Empty;
lsbActivities.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> strActivities = new List<string>();
TimeSpan tsTotal = new TimeSpan(0);
IEnumerable<IGrouping<string, KeyValuePair<string, TimeSpan>>> activityGroups = dictActivityHours
.GroupBy(p => p.Key.Split(' ').FirstOrDefault(), p => p)
.OrderBy(x => x.Key);
foreach (IGrouping<string, KeyValuePair<string, TimeSpan>> activityGroup in activityGroups)
{
TimeSpan tsActivityGroup = new TimeSpan(0);
foreach (KeyValuePair<string, TimeSpan> pair in activityGroup)
{
tsActivityGroup += pair.Value;
}
strActivities.Add(string.Format("{0} -- {1} h", activityGroup.Key, tsActivityGroup.TotalHours));
if (chkOnlyGroups.Checked == false)
{
foreach (KeyValuePair<string, TimeSpan> pair in activityGroup)
{
strActivities.Add(string.Format(" {0} -- {1} h", pair.Key, pair.Value.TotalHours));
tsTotal += pair.Value;
}
}
else
{
tsTotal += tsActivityGroup;
}
}
lsbActivities.Items.Clear();
lsbActivities.Items.AddRange(strActivities.ToArray());
lblTotalTime.Text = string.Format("{0} - {1}", tsTotal.ToString(), tsTotal.TotalHours);
}
private void lsbActivities_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control && e.KeyCode == Keys.C)
{
CopyToClipboard();
}
}
private void CopyToClipboard()
{
StringBuilder sbText = new StringBuilder();
foreach (string item in lsbActivities.SelectedItems)
{
sbText.AppendLine(item);
}
if (sbText.Length > 0)
{
Clipboard.SetText(sbText.ToString());
}
}
private void lsbActivities_SelectedIndexChanged(object sender, EventArgs e)
{
txtActivity.Text = (lsbActivities.SelectedItem as string) ?? string.Empty;
}
}
}

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -232,6 +232,12 @@
<Compile Include="UI\Tools\PnlSuspension.Designer.cs">
<DependentUpon>PnlSuspension.cs</DependentUpon>
</Compile>
<Compile Include="UI\Tools\WorkLog\FrmWorkLogSumary.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="UI\Tools\WorkLog\FrmWorkLogSumary.Designer.cs">
<DependentUpon>FrmWorkLogSumary.cs</DependentUpon>
</Compile>
<Compile Include="UI\Tools\WorkLog\FrmWorkLogStats.cs">
<SubType>Form</SubType>
</Compile>
@@ -251,6 +257,11 @@
<Content Include="Images\toolbox.svg" />
<Content Include="Toolbox.ico" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="UI\Tools\WorkLog\FrmWorkLogSumary.resx">
<DependentUpon>FrmWorkLogSumary.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.