From 6d80a5d553d93e2cf4ad744517bafdc4b2d5a266 Mon Sep 17 00:00:00 2001 From: "Valeriano A.R" Date: Wed, 8 Jul 2020 00:55:34 +0200 Subject: [PATCH] FrmWorkLogSumary: Form to sumarice a date range. --- .../UI/Tools/WorkLog/FrmWorkLog.Designer.cs | 35 ++-- VAR.Toolbox/UI/Tools/WorkLog/FrmWorkLog.cs | 6 + .../WorkLog/FrmWorkLogSumary.Designer.cs | 182 ++++++++++++++++++ .../UI/Tools/WorkLog/FrmWorkLogSumary.cs | 136 +++++++++++++ .../UI/Tools/WorkLog/FrmWorkLogSumary.resx | 120 ++++++++++++ VAR.Toolbox/VAR.Toolbox.csproj | 11 ++ 6 files changed, 479 insertions(+), 11 deletions(-) create mode 100644 VAR.Toolbox/UI/Tools/WorkLog/FrmWorkLogSumary.Designer.cs create mode 100644 VAR.Toolbox/UI/Tools/WorkLog/FrmWorkLogSumary.cs create mode 100644 VAR.Toolbox/UI/Tools/WorkLog/FrmWorkLogSumary.resx diff --git a/VAR.Toolbox/UI/Tools/WorkLog/FrmWorkLog.Designer.cs b/VAR.Toolbox/UI/Tools/WorkLog/FrmWorkLog.Designer.cs index b2ca22e..16efa06 100644 --- a/VAR.Toolbox/UI/Tools/WorkLog/FrmWorkLog.Designer.cs +++ b/VAR.Toolbox/UI/Tools/WorkLog/FrmWorkLog.Designer.cs @@ -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; } } \ No newline at end of file diff --git a/VAR.Toolbox/UI/Tools/WorkLog/FrmWorkLog.cs b/VAR.Toolbox/UI/Tools/WorkLog/FrmWorkLog.cs index c2433d4..b27141a 100644 --- a/VAR.Toolbox/UI/Tools/WorkLog/FrmWorkLog.cs +++ b/VAR.Toolbox/UI/Tools/WorkLog/FrmWorkLog.cs @@ -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; } diff --git a/VAR.Toolbox/UI/Tools/WorkLog/FrmWorkLogSumary.Designer.cs b/VAR.Toolbox/UI/Tools/WorkLog/FrmWorkLogSumary.Designer.cs new file mode 100644 index 0000000..2a3151f --- /dev/null +++ b/VAR.Toolbox/UI/Tools/WorkLog/FrmWorkLogSumary.Designer.cs @@ -0,0 +1,182 @@ +namespace VAR.Toolbox.UI.Tools.WorkLog +{ + partial class FrmWorkLogSumary + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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; + } +} \ No newline at end of file diff --git a/VAR.Toolbox/UI/Tools/WorkLog/FrmWorkLogSumary.cs b/VAR.Toolbox/UI/Tools/WorkLog/FrmWorkLogSumary.cs new file mode 100644 index 0000000..64721cc --- /dev/null +++ b/VAR.Toolbox/UI/Tools/WorkLog/FrmWorkLogSumary.cs @@ -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 _workLog = null; + + public List 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 dictActivityHours = new Dictionary(); + 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 strActivities = new List(); + TimeSpan tsTotal = new TimeSpan(0); + IEnumerable>> activityGroups = dictActivityHours + .GroupBy(p => p.Key.Split(' ').FirstOrDefault(), p => p) + .OrderBy(x => x.Key); + foreach (IGrouping> activityGroup in activityGroups) + { + TimeSpan tsActivityGroup = new TimeSpan(0); + foreach (KeyValuePair pair in activityGroup) + { + tsActivityGroup += pair.Value; + } + strActivities.Add(string.Format("{0} -- {1} h", activityGroup.Key, tsActivityGroup.TotalHours)); + if (chkOnlyGroups.Checked == false) + { + foreach (KeyValuePair 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; + } + } +} diff --git a/VAR.Toolbox/UI/Tools/WorkLog/FrmWorkLogSumary.resx b/VAR.Toolbox/UI/Tools/WorkLog/FrmWorkLogSumary.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/VAR.Toolbox/UI/Tools/WorkLog/FrmWorkLogSumary.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/VAR.Toolbox/VAR.Toolbox.csproj b/VAR.Toolbox/VAR.Toolbox.csproj index b878bfb..6cccdc4 100644 --- a/VAR.Toolbox/VAR.Toolbox.csproj +++ b/VAR.Toolbox/VAR.Toolbox.csproj @@ -232,6 +232,12 @@ PnlSuspension.cs + + Form + + + FrmWorkLogSumary.cs + Form @@ -251,6 +257,11 @@ + + + FrmWorkLogSumary.cs + +