From 640bed074a3aed5195e76b5c395194ced2fc5838 Mon Sep 17 00:00:00 2001 From: "Valeriano A.R" Date: Fri, 19 Jun 2020 01:51:16 +0200 Subject: [PATCH] FrmWorkLog: Search button for fast selection of activities. --- .../UI/Tools/WorkLog/FrmWorkLog.Designer.cs | 39 ++++++++++++------- VAR.Toolbox/UI/Tools/WorkLog/FrmWorkLog.cs | 22 +++++++++++ 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/VAR.Toolbox/UI/Tools/WorkLog/FrmWorkLog.Designer.cs b/VAR.Toolbox/UI/Tools/WorkLog/FrmWorkLog.Designer.cs index 9da8f8e..b2ca22e 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.btnStats = new System.Windows.Forms.Button(); this.lblWorkLogItemTime = new System.Windows.Forms.Label(); this.btnRename = new System.Windows.Forms.Button(); this.dtEnd = new System.Windows.Forms.DateTimePicker(); @@ -48,7 +49,7 @@ this.txtActivity = new System.Windows.Forms.TextBox(); this.btnDelete = new System.Windows.Forms.Button(); this.btnAdd = new System.Windows.Forms.Button(); - this.btnStats = new System.Windows.Forms.Button(); + this.btnSearch = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.splitWindow)).BeginInit(); this.splitWindow.Panel1.SuspendLayout(); this.splitWindow.Panel2.SuspendLayout(); @@ -77,6 +78,7 @@ // // splitWindow.Panel2 // + this.splitWindow.Panel2.Controls.Add(this.btnSearch); this.splitWindow.Panel2.Controls.Add(this.btnStats); this.splitWindow.Panel2.Controls.Add(this.lblWorkLogItemTime); this.splitWindow.Panel2.Controls.Add(this.btnRename); @@ -211,6 +213,17 @@ this.lsbWorkLog.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.lsbWorkLog_DrawItem); this.lsbWorkLog.SelectedIndexChanged += new System.EventHandler(this.lsbWorkLog_SelectedIndexChanged); // + // btnStats + // + this.btnStats.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnStats.Location = new System.Drawing.Point(207, 3); + 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); + // // lblWorkLogItemTime // this.lblWorkLogItemTime.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) @@ -224,8 +237,7 @@ // // btnRename // - this.btnRename.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.btnRename.Location = new System.Drawing.Point(207, 3); + this.btnRename.Location = new System.Drawing.Point(6, 119); this.btnRename.Name = "btnRename"; this.btnRename.Size = new System.Drawing.Size(56, 22); this.btnRename.TabIndex = 6; @@ -260,11 +272,11 @@ this.txtDescription.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.txtDescription.Location = new System.Drawing.Point(4, 119); + this.txtDescription.Location = new System.Drawing.Point(4, 147); this.txtDescription.Multiline = true; this.txtDescription.Name = "txtDescription"; this.txtDescription.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; - this.txtDescription.Size = new System.Drawing.Size(259, 472); + this.txtDescription.Size = new System.Drawing.Size(259, 444); this.txtDescription.TabIndex = 3; this.txtDescription.TextChanged += new System.EventHandler(this.txtDescription_TextChanged); // @@ -298,15 +310,15 @@ this.btnAdd.UseVisualStyleBackColor = true; this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click); // - // btnStats + // btnSearch // - 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); + 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); // // FrmWorkLog // @@ -350,5 +362,6 @@ private System.Windows.Forms.Label lblWorkLogItemTime; private System.Windows.Forms.Label lblWorkLogTime; private System.Windows.Forms.Button btnStats; + private System.Windows.Forms.Button btnSearch; } } \ 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 a75842d..c2433d4 100644 --- a/VAR.Toolbox/UI/Tools/WorkLog/FrmWorkLog.cs +++ b/VAR.Toolbox/UI/Tools/WorkLog/FrmWorkLog.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Drawing; using System.IO; +using System.Linq; using System.Text; using System.Windows.Forms; using VAR.Json; @@ -241,6 +242,27 @@ namespace VAR.Toolbox.UI.Tools.WorkLog FrmWorkLogStats frmStats = new FrmWorkLogStats { Activity = _currentWorkLogItem.Activity, WorkLog = _workLog }; frmStats.ShowDialog(this); } + private void btnSearch_Click(object sender, EventArgs e) + { + if (_workLog == null) { return; } + + List listActivities = _workLog + .GroupBy(x => x.Activity) + .Select(g => g.OrderBy(x => x.DateStart).LastOrDefault()) + .OrderByDescending(x => x.DateStart) + .Select(x => x.Activity) + .ToList(); + + FrmListBoxDialog frmListDialog = new FrmListBoxDialog(); + frmListDialog.Title = "Search Activity"; + frmListDialog.LoadItems(listActivities); + + DialogResult result = frmListDialog.ShowDialog(this); + if (result != DialogResult.OK) { return; } + + if (string.IsNullOrEmpty(frmListDialog.Value)) { return; } + txtActivity.Text = frmListDialog.Value; + } #endregion UI events