FrmWorkLog: Better worklog viewer

This commit is contained in:
2020-06-10 02:07:05 +02:00
parent 5cd2983fe4
commit 0af7d299c9
2 changed files with 43 additions and 19 deletions

View File

@@ -176,14 +176,17 @@
| System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.lsbWorkLog.BackColor = System.Drawing.Color.Black; this.lsbWorkLog.BackColor = System.Drawing.Color.Black;
this.lsbWorkLog.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable;
this.lsbWorkLog.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lsbWorkLog.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lsbWorkLog.ForeColor = System.Drawing.Color.Gray; this.lsbWorkLog.ForeColor = System.Drawing.Color.Gray;
this.lsbWorkLog.FormattingEnabled = true; this.lsbWorkLog.FormattingEnabled = true;
this.lsbWorkLog.ItemHeight = 12;
this.lsbWorkLog.Location = new System.Drawing.Point(3, 60); this.lsbWorkLog.Location = new System.Drawing.Point(3, 60);
this.lsbWorkLog.Name = "lsbWorkLog"; this.lsbWorkLog.Name = "lsbWorkLog";
this.lsbWorkLog.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended; this.lsbWorkLog.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;
this.lsbWorkLog.Size = new System.Drawing.Size(436, 537); this.lsbWorkLog.Size = new System.Drawing.Size(436, 532);
this.lsbWorkLog.TabIndex = 0; this.lsbWorkLog.TabIndex = 0;
this.lsbWorkLog.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.lsbWorkLog_DrawItem);
this.lsbWorkLog.SelectedIndexChanged += new System.EventHandler(this.lsbWorkLog_SelectedIndexChanged); this.lsbWorkLog.SelectedIndexChanged += new System.EventHandler(this.lsbWorkLog_SelectedIndexChanged);
// //
// dtEnd // dtEnd

View File

@@ -1,7 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing;
using System.IO; using System.IO;
using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using VAR.Json; using VAR.Json;
@@ -198,6 +198,22 @@ namespace VAR.Toolbox.UI.Tools.WorkLog
dtToday.Value = dtToday.Value.Date.AddDays(1); dtToday.Value = dtToday.Value.Date.AddDays(1);
} }
private void lsbWorkLog_DrawItem(object sender, DrawItemEventArgs e)
{
if (e.Index < 0) return;
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
{
e.Graphics.FillRectangle(Brushes.DarkRed, e.Bounds);
e.Graphics.DrawString(lsbWorkLog.Items[e.Index].ToString(), lsbWorkLog.Font, Brushes.Black, e.Bounds);
}
else
{
e.Graphics.FillRectangle(Brushes.Black, e.Bounds);
e.Graphics.DrawString(lsbWorkLog.Items[e.Index].ToString(), lsbWorkLog.Font, Brushes.Gray, e.Bounds);
}
}
#endregion UI events #endregion UI events
#region Private methods #region Private methods
@@ -306,8 +322,13 @@ namespace VAR.Toolbox.UI.Tools.WorkLog
private void WorkLog_Refresh() private void WorkLog_Refresh()
{ {
int selectedIndex = lsbWorkLog.SelectedIndex;
DateTime today = dtToday.Value; DateTime today = dtToday.Value;
lsbWorkLog_BindData(_workLog, today.Year, today.Month, today.Day); lsbWorkLog_BindData(_workLog, today.Year, today.Month, today.Day);
if (selectedIndex > -1)
{
lsbWorkLog.SelectedIndex = selectedIndex;
}
} }
private WorkLogItem _currentWorkLogItem = null; private WorkLogItem _currentWorkLogItem = null;
@@ -353,6 +374,7 @@ namespace VAR.Toolbox.UI.Tools.WorkLog
public void lsbWorkLog_BindData(IEnumerable<WorkLogItem> items, int year, int month, int day, int q = 15) public void lsbWorkLog_BindData(IEnumerable<WorkLogItem> items, int year, int month, int day, int q = 15)
{ {
int topIndex = lsbWorkLog.TopIndex;
List<WorkLogRow> rows = new List<WorkLogRow>(); List<WorkLogRow> rows = new List<WorkLogRow>();
for (int h = 0; h < 24; h++) for (int h = 0; h < 24; h++)
{ {
@@ -373,20 +395,21 @@ namespace VAR.Toolbox.UI.Tools.WorkLog
} }
lsbWorkLog.Items.Clear(); lsbWorkLog.Items.Clear();
lsbWorkLog.Items.AddRange(rows.ToArray()); lsbWorkLog.Items.AddRange(rows.ToArray());
lsbWorkLog.TopIndex = topIndex;
EnableRepaint(new HandleRef(lsbWorkLog, lsbWorkLog.Handle), true); //EnableRepaint(new HandleRef(lsbWorkLog, lsbWorkLog.Handle), true);
lsbWorkLog.Invalidate(); //lsbWorkLog.Invalidate();
} }
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)] //[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
private static extern IntPtr SendMessage(HandleRef hWnd, Int32 Msg, IntPtr wParam, IntPtr lParam); //private static extern IntPtr SendMessage(HandleRef hWnd, Int32 Msg, IntPtr wParam, IntPtr lParam);
private static void EnableRepaint(HandleRef handle, bool enable) //private static void EnableRepaint(HandleRef handle, bool enable)
{ //{
const int WM_SETREDRAW = 0x000B; // const int WM_SETREDRAW = 0x000B;
SendMessage(handle, WM_SETREDRAW, new IntPtr(enable ? 1 : 0), IntPtr.Zero); // SendMessage(handle, WM_SETREDRAW, new IntPtr(enable ? 1 : 0), IntPtr.Zero);
} //}
#endregion Private methods #endregion Private methods
@@ -417,32 +440,30 @@ namespace VAR.Toolbox.UI.Tools.WorkLog
{ {
if (Item.DateEnd >= DateStart && Item.DateEnd <= DateEnd) if (Item.DateEnd >= DateStart && Item.DateEnd <= DateEnd)
{ {
sbRow.Append("- "); sbRow.Append(" ");
sbRow.Append(Item.Activity); sbRow.Append(Item.Activity);
sbRow.Append(" "); sbRow.Append(" ");
sbRow.Append(new string('-', (rowLenght - textLenght) + 1)); sbRow.Append(new string('', (rowLenght - textLenght) + 1));
} }
else else
{ {
sbRow.Append("┌ "); sbRow.Append("┌ ");
sbRow.Append(Item.Activity); sbRow.Append(Item.Activity);
sbRow.Append(" "); sbRow.Append(" ");
sbRow.Append(new string('-', rowLenght - textLenght)); sbRow.Append(new string('', rowLenght - textLenght));
sbRow.Append("┐"); sbRow.Append("┐");
} }
} }
else if (Item.DateEnd >= DateStart && Item.DateEnd <= DateEnd) else if (Item.DateEnd >= DateStart && Item.DateEnd <= DateEnd)
{ {
sbRow.Append("└ "); sbRow.Append("└");
sbRow.Append(Item.Activity); sbRow.Append(new string('─', rowLenght));
sbRow.Append(" ");
sbRow.Append(new string('-', rowLenght - textLenght));
sbRow.Append("┘"); sbRow.Append("┘");
} }
else else
{ {
sbRow.Append("│"); sbRow.Append("│");
sbRow.Append(new string('#', rowLenght)); sbRow.Append(new string(' ', rowLenght));
sbRow.Append("│"); sbRow.Append("│");
} }
return sbRow.ToString(); return sbRow.ToString();