finish reports section

This commit is contained in:
Spudnut2000 2025-06-26 20:59:06 -05:00
parent 1764749ecc
commit 0bcfa4665c
3 changed files with 82 additions and 15 deletions

View File

@ -39,19 +39,23 @@ partial class ReportsForm
userScheduleDataGrid = new System.Windows.Forms.DataGridView();
userComboBox = new System.Windows.Forms.ComboBox();
refreshButton2 = new System.Windows.Forms.Button();
customersByCountryTabPage = new System.Windows.Forms.TabPage();
customersByCityTabPage = new System.Windows.Forms.TabPage();
refreshButton3 = new System.Windows.Forms.Button();
customersByCityDataGrid = new System.Windows.Forms.DataGridView();
tabControl1.SuspendLayout();
apptByMothTabPage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)apptByMonthDataGrid).BeginInit();
userSchedulesTabPage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)userScheduleDataGrid).BeginInit();
customersByCityTabPage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)customersByCityDataGrid).BeginInit();
SuspendLayout();
//
// tabControl1
//
tabControl1.Controls.Add(apptByMothTabPage);
tabControl1.Controls.Add(userSchedulesTabPage);
tabControl1.Controls.Add(customersByCountryTabPage);
tabControl1.Controls.Add(customersByCityTabPage);
tabControl1.Location = new System.Drawing.Point(12, 12);
tabControl1.Name = "tabControl1";
tabControl1.SelectedIndex = 0;
@ -124,14 +128,33 @@ partial class ReportsForm
refreshButton2.Text = "Refresh";
refreshButton2.UseVisualStyleBackColor = true;
//
// customersByCountryTabPage
// customersByCityTabPage
//
customersByCountryTabPage.Location = new System.Drawing.Point(4, 24);
customersByCountryTabPage.Name = "customersByCountryTabPage";
customersByCountryTabPage.Size = new System.Drawing.Size(768, 398);
customersByCountryTabPage.TabIndex = 2;
customersByCountryTabPage.Text = "Customers By Country";
customersByCountryTabPage.UseVisualStyleBackColor = true;
customersByCityTabPage.Controls.Add(refreshButton3);
customersByCityTabPage.Controls.Add(customersByCityDataGrid);
customersByCityTabPage.Location = new System.Drawing.Point(4, 24);
customersByCityTabPage.Name = "customersByCityTabPage";
customersByCityTabPage.Size = new System.Drawing.Size(768, 398);
customersByCityTabPage.TabIndex = 2;
customersByCityTabPage.Text = "Customers By City";
customersByCityTabPage.UseVisualStyleBackColor = true;
//
// refreshButton3
//
refreshButton3.Location = new System.Drawing.Point(675, 372);
refreshButton3.Name = "refreshButton3";
refreshButton3.Size = new System.Drawing.Size(90, 23);
refreshButton3.TabIndex = 3;
refreshButton3.Text = "Refresh";
refreshButton3.UseVisualStyleBackColor = true;
//
// customersByCityDataGrid
//
customersByCityDataGrid.Location = new System.Drawing.Point(3, 3);
customersByCityDataGrid.Name = "customersByCityDataGrid";
customersByCityDataGrid.ReadOnly = true;
customersByCityDataGrid.Size = new System.Drawing.Size(762, 363);
customersByCityDataGrid.TabIndex = 2;
//
// ReportsForm
//
@ -145,9 +168,14 @@ partial class ReportsForm
((System.ComponentModel.ISupportInitialize)apptByMonthDataGrid).EndInit();
userSchedulesTabPage.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)userScheduleDataGrid).EndInit();
customersByCityTabPage.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)customersByCityDataGrid).EndInit();
ResumeLayout(false);
}
private System.Windows.Forms.DataGridView customersByCityDataGrid;
private System.Windows.Forms.Button refreshButton3;
private System.Windows.Forms.DataGridView userScheduleDataGrid;
private System.Windows.Forms.ComboBox userComboBox;
@ -156,7 +184,7 @@ partial class ReportsForm
private System.Windows.Forms.Button refreshButton1;
private System.Windows.Forms.TabPage customersByCountryTabPage;
private System.Windows.Forms.TabPage customersByCityTabPage;
private System.Windows.Forms.DataGridView apptByMonthDataGrid;
private System.Windows.Forms.TabControl tabControl1;

View File

@ -25,12 +25,15 @@ public partial class ReportsForm : Form
UserSchedule_UpdateUsers();
userComboBox.SelectedIndexChanged += (sender, args) => { UserSchedule_GenerateReport(); };
userComboBox.SelectedIndex = -1; // Reset selection
userComboBox.SelectedIndex = -1;
refreshButton2.Click += (sender, args) =>
{
UserSchedule_UpdateUsers();
UserSchedule_GenerateReport();
};
CustomersByCity_GenerateReport();
refreshButton3.Click += (sender, args) => { CustomersByCity_GenerateReport(); };
}
#region Apptointments types by Month
@ -130,4 +133,40 @@ public partial class ReportsForm : Form
}
#endregion
#region Number of Users by City
private void CustomersByCity_GenerateReport()
{
customersByCityDataGrid.DataSource = null;
var customers = DatabaseHelper.RetrieveCustomers();
var cityCounts = customers
.Select(c =>
{
var addr = DatabaseHelper.RetrieveAddress(c.AddressId);
var city = addr != null ? DatabaseHelper.RetrieveCity(addr.CityId) : null;
return city?.CityName;
})
.Where(cityName => !string.IsNullOrEmpty(cityName))
.GroupBy(cityName => cityName)
.Select(g => new CustomersByCity(g.Key, g.Count()))
.ToList();
customersByCityDataGrid.DataSource = cityCounts;
}
private class CustomersByCity
{
public string? City { get; set; }
public int UserCount { get; set; }
public CustomersByCity(string? city, int userCount)
{
City = city;
UserCount = userCount;
}
}
#endregion
}

View File

@ -63,10 +63,10 @@
## 7. Reports
- [ ] Create a report generator using collection classes and lambda expressions:
- [ ] Report: Number of appointment types by month
- [ ] Report: Schedule for each user
- [ ] Report: One additional report of your choice
- [x] Create a report generator using collection classes and lambda expressions:
- [x] Report: Number of appointment types by month
- [x] Report: Schedule for each user
- [x] Report: One additional report of your choice
## 8. Login History