diff --git a/Source/LibationWinForms/grid/EditTagsDataGridViewImageButtonColumn.cs b/Source/LibationWinForms/grid/EditTagsDataGridViewImageButtonColumn.cs index db8bb484..b0d9407e 100644 --- a/Source/LibationWinForms/grid/EditTagsDataGridViewImageButtonColumn.cs +++ b/Source/LibationWinForms/grid/EditTagsDataGridViewImageButtonColumn.cs @@ -21,7 +21,7 @@ namespace LibationWinForms { if (rowIndex >= 0 && DataGridView.GetBoundItem(rowIndex) is SeriesEntry) { - base.Paint(graphics, clipBounds, cellBounds, rowIndex, DataGridViewElementStates.None, null, null, null, cellStyle, advancedBorderStyle, DataGridViewPaintParts.Background | DataGridViewPaintParts.Border); + base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, null, null, null, cellStyle, advancedBorderStyle, DataGridViewPaintParts.Background | DataGridViewPaintParts.Border); return; } diff --git a/Source/LibationWinForms/grid/LiberateDataGridViewImageButtonColumn.cs b/Source/LibationWinForms/grid/LiberateDataGridViewImageButtonColumn.cs index 159b1e4a..9d97dca9 100644 --- a/Source/LibationWinForms/grid/LiberateDataGridViewImageButtonColumn.cs +++ b/Source/LibationWinForms/grid/LiberateDataGridViewImageButtonColumn.cs @@ -25,13 +25,11 @@ namespace LibationWinForms if (status.IsSeries) { var imageName = status.Expanded ? "minus" : "plus"; - var text = status.Expanded ? "Click to Collpase" : "Click to Expand"; var bmp = (Bitmap)Properties.Resources.ResourceManager.GetObject(imageName); DrawButtonImage(graphics, bmp, cellBounds); - ToolTipText = text; - + ToolTipText = status.Expanded ? "Click to Collpase" : "Click to Expand"; } else { diff --git a/Source/LibationWinForms/grid/ProductsDisplay.Designer.cs b/Source/LibationWinForms/grid/ProductsDisplay.Designer.cs index a10e1c95..8f561b0f 100644 --- a/Source/LibationWinForms/grid/ProductsDisplay.Designer.cs +++ b/Source/LibationWinForms/grid/ProductsDisplay.Designer.cs @@ -53,7 +53,6 @@ this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.Name = "ProductsDisplay"; this.Size = new System.Drawing.Size(1510, 380); - this.Load += new System.EventHandler(this.ProductsDisplay_Load); this.ResumeLayout(false); } diff --git a/Source/LibationWinForms/grid/ProductsDisplay.cs b/Source/LibationWinForms/grid/ProductsDisplay.cs index 0a9bee61..6fc37fa0 100644 --- a/Source/LibationWinForms/grid/ProductsDisplay.cs +++ b/Source/LibationWinForms/grid/ProductsDisplay.cs @@ -14,23 +14,18 @@ namespace LibationWinForms { public partial class ProductsDisplay : UserControl { - public event EventHandler LiberateClicked; /// Number of visible rows has changed public event EventHandler VisibleCountChanged; + public event EventHandler LiberateClicked; + public event EventHandler InitialLoaded; + + private bool hasBeenDisplayed; public ProductsDisplay() { InitializeComponent(); } - private void ProductsDisplay_Load(object sender, EventArgs e) - { - if (DesignMode) - return; - - } - - #region Button controls private ImageDisplay imageDisplay; @@ -76,7 +71,6 @@ namespace LibationWinForms displayWindow.Show(this); } - private void productsGrid_DetailsClicked(LibraryBookEntry liveGridEntry) { var bookDetailsForm = new BookDetailsDialog(liveGridEntry.LibraryBook); @@ -88,8 +82,6 @@ namespace LibationWinForms #region UI display functions - private bool hasBeenDisplayed; - public event EventHandler InitialLoaded; public void Display() { // don't return early if lib size == 0. this will not update correctly if all books are removed diff --git a/Source/LibationWinForms/grid/ProductsGrid.Designer.cs b/Source/LibationWinForms/grid/ProductsGrid.Designer.cs index e818ed5b..cd312da0 100644 --- a/Source/LibationWinForms/grid/ProductsGrid.Designer.cs +++ b/Source/LibationWinForms/grid/ProductsGrid.Designer.cs @@ -29,7 +29,7 @@ private void InitializeComponent() { this.components = new System.ComponentModel.Container(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); this.gridEntryDataGridView = new System.Windows.Forms.DataGridView(); this.liberateGVColumn = new LibationWinForms.LiberateDataGridViewImageButtonColumn(); this.coverGVColumn = new System.Windows.Forms.DataGridViewImageColumn(); @@ -46,7 +46,11 @@ this.miscGVColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.tagAndDetailsGVColumn = new LibationWinForms.EditTagsDataGridViewImageButtonColumn(); this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); + this.syncBindingSource = new LibationWinForms.SyncBindingSource(this.components); + this.bindingSource = new System.Windows.Forms.BindingSource(this.components); ((System.ComponentModel.ISupportInitialize)(this.gridEntryDataGridView)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.syncBindingSource)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.bindingSource)).BeginInit(); this.SuspendLayout(); // // gridEntryDataGridView @@ -55,6 +59,7 @@ this.gridEntryDataGridView.AllowUserToDeleteRows = false; this.gridEntryDataGridView.AllowUserToOrderColumns = true; this.gridEntryDataGridView.AllowUserToResizeRows = false; + this.gridEntryDataGridView.AutoGenerateColumns = false; this.gridEntryDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.gridEntryDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.liberateGVColumn, @@ -72,14 +77,15 @@ this.miscGVColumn, this.tagAndDetailsGVColumn}); this.gridEntryDataGridView.ContextMenuStrip = this.contextMenuStrip1; - dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; - dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Window; - dataGridViewCellStyle1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.ControlText; - dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText; - dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True; - this.gridEntryDataGridView.DefaultCellStyle = dataGridViewCellStyle1; + this.gridEntryDataGridView.DataSource = this.syncBindingSource; + dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Window; + dataGridViewCellStyle2.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.ControlText; + dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.gridEntryDataGridView.DefaultCellStyle = dataGridViewCellStyle2; this.gridEntryDataGridView.Dock = System.Windows.Forms.DockStyle.Fill; this.gridEntryDataGridView.Location = new System.Drawing.Point(0, 0); this.gridEntryDataGridView.Name = "gridEntryDataGridView"; @@ -90,7 +96,6 @@ this.gridEntryDataGridView.TabIndex = 0; this.gridEntryDataGridView.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.DataGridView_CellContentClick); this.gridEntryDataGridView.CellToolTipTextNeeded += new System.Windows.Forms.DataGridViewCellToolTipTextNeededEventHandler(this.gridEntryDataGridView_CellToolTipTextNeeded); - this.gridEntryDataGridView.ColumnDisplayIndexChanged += new System.Windows.Forms.DataGridViewColumnEventHandler(this.gridEntryDataGridView_ColumnDisplayIndexChanged); // // liberateGVColumn // @@ -209,6 +214,14 @@ this.contextMenuStrip1.Name = "contextMenuStrip1"; this.contextMenuStrip1.Size = new System.Drawing.Size(61, 4); // + // syncBindingSource + // + this.syncBindingSource.DataSource = this.bindingSource; + // + // bindingSource + // + this.bindingSource.DataSource = typeof(LibationWinForms.GridEntry); + // // ProductsGrid // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -219,6 +232,8 @@ this.Size = new System.Drawing.Size(1510, 380); this.Load += new System.EventHandler(this.ProductsGrid_Load); ((System.ComponentModel.ISupportInitialize)(this.gridEntryDataGridView)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.syncBindingSource)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.bindingSource)).EndInit(); this.ResumeLayout(false); } @@ -241,5 +256,7 @@ private System.Windows.Forms.DataGridViewTextBoxColumn myRatingGVColumn; private System.Windows.Forms.DataGridViewTextBoxColumn miscGVColumn; private EditTagsDataGridViewImageButtonColumn tagAndDetailsGVColumn; + private SyncBindingSource syncBindingSource; + private System.Windows.Forms.BindingSource bindingSource; } } diff --git a/Source/LibationWinForms/grid/ProductsGrid.cs b/Source/LibationWinForms/grid/ProductsGrid.cs index b119285d..0593d743 100644 --- a/Source/LibationWinForms/grid/ProductsGrid.cs +++ b/Source/LibationWinForms/grid/ProductsGrid.cs @@ -24,15 +24,14 @@ namespace LibationWinForms.grid public new event EventHandler Scroll; private FilterableSortableBindingList bindingList; - private SyncBindingSource gridEntryBindingSource; + internal IEnumerable GetVisible() + => bindingList + .LibraryBooks(); public ProductsGrid() { InitializeComponent(); EnableDoubleBuffering(); - //There a bug in designer that causes errors if you add BindingSource to the DataGridView at design time. - gridEntryBindingSource = new SyncBindingSource(); - gridEntryDataGridView.DataSource = gridEntryBindingSource; gridEntryDataGridView.Scroll += (_, s) => Scroll?.Invoke(this, s); } @@ -105,14 +104,14 @@ namespace LibationWinForms.grid bindingList = new FilterableSortableBindingList(geList.OrderByDescending(e => e.DateAdded)); bindingList.CollapseAll(); - gridEntryBindingSource.DataSource = bindingList; + syncBindingSource.DataSource = bindingList; VisibleCountChanged?.Invoke(this, bindingList.LibraryBooks().Count()); } internal void UpdateGrid(List dbBooks) { int visibleCount = bindingList.Count; - string existingFilter = gridEntryBindingSource.Filter; + string existingFilter = syncBindingSource.Filter; //Add absent books to grid, or update current books @@ -206,9 +205,9 @@ namespace LibationWinForms.grid int visibleCount = bindingList.Count; if (string.IsNullOrEmpty(searchString)) - gridEntryBindingSource.RemoveFilter(); + syncBindingSource.RemoveFilter(); else - gridEntryBindingSource.Filter = searchString; + syncBindingSource.Filter = searchString; if (visibleCount != bindingList.Count) VisibleCountChanged?.Invoke(this, bindingList.LibraryBooks().Count()); @@ -217,13 +216,15 @@ namespace LibationWinForms.grid #endregion - internal IEnumerable GetVisible() - => bindingList - .LibraryBooks(); + #region Column Customizations private void ProductsGrid_Load(object sender, EventArgs e) { + //https://stackoverflow.com/a/4498512/3335599 + if (System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime) return; + gridEntryDataGridView.ColumnWidthChanged += gridEntryDataGridView_ColumnWidthChanged; + gridEntryDataGridView.ColumnDisplayIndexChanged += gridEntryDataGridView_ColumnDisplayIndexChanged; contextMenuStrip1.Items.Add(new ToolStripLabel("Show / Hide Columns")); contextMenuStrip1.Items.Add(new ToolStripSeparator()); @@ -272,6 +273,7 @@ namespace LibationWinForms.grid column.DisplayIndex = displayIndices.GetValueOrDefault(itemName, column.Index); } } + private void HideMenuItem_Click(object sender, EventArgs e) { var menuItem = sender as ToolStripMenuItem; @@ -319,5 +321,7 @@ namespace LibationWinForms.grid var dictionary = config.GridColumnsWidths; dictionary[e.Column.DataPropertyName] = e.Column.Width; } + + #endregion } } diff --git a/Source/LibationWinForms/grid/ProductsGrid.resx b/Source/LibationWinForms/grid/ProductsGrid.resx index 2a349cc7..bc15cd01 100644 --- a/Source/LibationWinForms/grid/ProductsGrid.resx +++ b/Source/LibationWinForms/grid/ProductsGrid.resx @@ -58,6 +58,15 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + 171, 17 + + 17, 17 + + 326, 17 + + + 326, 17 + \ No newline at end of file diff --git a/Source/LibationWinForms/grid/SeriesEntry.cs b/Source/LibationWinForms/grid/SeriesEntry.cs index 22252e7b..afe21444 100644 --- a/Source/LibationWinForms/grid/SeriesEntry.cs +++ b/Source/LibationWinForms/grid/SeriesEntry.cs @@ -14,17 +14,41 @@ namespace LibationWinForms { public List Children { get; set; } public override DateTime DateAdded => Children.Max(c => c.DateAdded); - public override string ProductRating { get; protected set; } + public override string ProductRating + { + get + { + var productAverageRating = new Rating(Children.Average(c => c.LibraryBook.Book.Rating.OverallRating), Children.Average(c => c.LibraryBook.Book.Rating.PerformanceRating), Children.Average(c => c.LibraryBook.Book.Rating.StoryRating)); + return productAverageRating.ToStarString()?.DefaultIfNullOrWhiteSpace(""); + } + protected set => throw new NotImplementedException(); + } public override string PurchaseDate { get; protected set; } - public override string MyRating { get; protected set; } + public override string MyRating + { + get + { + var myAverageRating = new Rating(Children.Average(c => c.LibraryBook.Book.UserDefinedItem.Rating.OverallRating), Children.Average(c => c.LibraryBook.Book.UserDefinedItem.Rating.PerformanceRating), Children.Average(c => c.LibraryBook.Book.UserDefinedItem.Rating.StoryRating)); + return myAverageRating.ToStarString()?.DefaultIfNullOrWhiteSpace(""); + } + protected set => throw new NotImplementedException(); + } public override string Series { get; protected set; } public override string Title { get; protected set; } - public override string Length { get; protected set; } + public override string Length + { + get + { + int bookLenMins = Children.Sum(c => c.LibraryBook.Book.LengthInMinutes); + return bookLenMins == 0 ? "" : $"{bookLenMins / 60} hr {bookLenMins % 60} min"; + } + protected set => throw new NotImplementedException(); + } public override string Authors { get; protected set; } public override string Narrators { get; protected set; } public override string Category { get; protected set; } - public override string Misc { get; protected set; } - public override string Description { get; protected set; } + public override string Misc { get; protected set; } = string.Empty; + public override string Description { get; protected set; } = string.Empty; public override string DisplayTags { get; } = string.Empty; public override LiberateStatus Liberate => _liberate; @@ -34,6 +58,7 @@ namespace LibationWinForms private SeriesBook SeriesBook { get; set; } private LiberateStatus _liberate = new LiberateStatus { IsSeries = true }; + public void setSeriesBook(SeriesBook seriesBook) { SeriesBook = seriesBook; @@ -42,18 +67,9 @@ namespace LibationWinForms // Immutable properties { - int bookLenMins = Children.Sum(c => c.LibraryBook.Book.LengthInMinutes); - - var myAverageRating = new Rating(Children.Average(c => c.LibraryBook.Book.UserDefinedItem.Rating.OverallRating), Children.Average(c => c.LibraryBook.Book.UserDefinedItem.Rating.PerformanceRating), Children.Average(c => c.LibraryBook.Book.UserDefinedItem.Rating.StoryRating)); - var productAverageRating = new Rating(Children.Average(c => c.LibraryBook.Book.Rating.OverallRating), Children.Average(c => c.LibraryBook.Book.Rating.PerformanceRating), Children.Average(c => c.LibraryBook.Book.Rating.StoryRating)); - - Title = SeriesBook.Series.Name; Series = SeriesBook.Series.Name; - Length = bookLenMins == 0 ? "" : $"{bookLenMins / 60} hr {bookLenMins % 60} min"; - MyRating = myAverageRating.ToStarString()?.DefaultIfNullOrWhiteSpace(""); PurchaseDate = Children.Min(c => c.LibraryBook.DateAdded).ToString("d"); - ProductRating = productAverageRating.ToStarString()?.DefaultIfNullOrWhiteSpace(""); Authors = Book.AuthorNames(); Narrators = Book.NarratorNames(); Category = string.Join(" > ", Book.CategoriesNames());