private void ReportLV_ColumnClick(object sender, ColumnClickEventArgs e) { // Determine whether the column is the same as the last column clicked. if (e.Column != sortColumn) { // Set the sort column to the new column. sortColumn = e.Column; // Set the sort order to ascending by default. ReportLV.Sorting = SortOrder.Ascending; } else { // Determine what the last sort order was and change it. if (ReportLV.Sorting == SortOrder.Ascending) { ReportLV.Sorting = SortOrder.Descending; } else { ReportLV.Sorting = SortOrder.Ascending; } } // Set the ListViewItemSorter property to a new ListViewItemComparer // object. ReportLV.ListViewItemSorter = new ListViewItemComparer(e.Column, ReportLV.Sorting); // Call the sort method to manually sort. ReportLV.Sort(); }
private void ModeCB_SelectedIndexChanged(object sender, EventArgs e) { ReportLV.Clear(); initReportLV(); if (ModeCB.Text == "Daily") { showDailyReport(); } else if (ModeCB.Text == "Monthly") { showMonthlyReport(); } else if (ModeCB.Text == "Yearly") { showYearlyReport(); } else if (ModeCB.Text == "Quantity") { showQuantityReport(); } int totalsold = 0; double totalincome = 0; for (int i = 0; i < report.Count; i++) { totalsold = totalsold + report[i].quantity; totalincome = totalincome + report[i].price; } TotalSoldLB.Text = "Total Item(s) Sold = " + totalsold.ToString(); TotalIncomeLB.Text = "Total Income = RM" + totalincome.ToString("F"); }
private void showQuantityReport() { ReportLV.Clear(); // Reset ReportLV.Columns.Add("Date", 150, HorizontalAlignment.Left); ReportLV.Columns.Add("Item(s) Sold", 200, HorizontalAlignment.Right); ReportLV.Columns.Add("Item Name", 200, HorizontalAlignment.Left); ReportLV.View = View.Details; // Manual sort for (int i = 0; i < report.Count; i++) { ListViewItem listViewItem = new ListViewItem(new string[] { report[i].date.ToString(), report[i].quantity.ToString(), report[i].itemName.ToString() }); ReportLV.Items.AddRange(new ListViewItem[] { listViewItem }); } }
private void showYearlyReport() { // show all yearly List <DateTime> yearly = new List <DateTime>(); // add all date for (int i = 0; i < report.Count; i++) { yearly.Add(report[i].date); } // delete repeated days for (int x = 0; x < report.Count; x++) { for (int i = 0; i < yearly.Count; i++) { for (int j = 0; j < yearly.Count; j++) { if (j != i) { if (yearly[i].Year == yearly[j].Year) { yearly.RemoveAt(i); } } } } } // find total item sold int[] Sold = new int[yearly.Count]; for (int i = 0; i < yearly.Count; i++) { for (int j = 0; j < report.Count; j++) { if (yearly[i].Year == report[j].date.Year) { Sold[i] = Sold[i] + report[j].quantity; } } } // find total income double[] Income = new double[yearly.Count]; for (int i = 0; i < yearly.Count; i++) { for (int j = 0; j < report.Count; j++) { if (yearly[i].Year == report[j].date.Year) { Income[i] = Income[i] + report[j].price; } } } for (int i = 0; i < yearly.Count; i++) { ListViewItem listViewItem = new ListViewItem(new string[] { yearly[i].ToString("yyyy"), Sold[i].ToString(), Income[i].ToString("F") }); ReportLV.Items.AddRange(new ListViewItem[] { listViewItem }); } ReportLV.ListViewItemSorter = new ListViewItemComparer(); ReportLV.Sort(); }
private void showMonthlyReport() { // show all month List <DateTime> monthly = new List <DateTime>(); // add all date for (int i = 0; i < report.Count; i++) { monthly.Add(report[i].date); } // delete repeated days for (int x = 0; x < report.Count; x++) { bool breaki = false; for (int i = 0; i < monthly.Count; i++) { for (int j = 0; j < monthly.Count; j++) { if (j != i) { if (monthly[i].Year == monthly[j].Year) { if (monthly[i].Month == monthly[j].Month) { monthly.RemoveAt(i); breaki = true; break; } } } } if (breaki) { break; } } } // find total item sold int[] Sold = new int[monthly.Count]; for (int i = 0; i < monthly.Count; i++) { for (int j = 0; j < report.Count; j++) { if (monthly[i].Year == report[j].date.Year) { if (monthly[i].Month == report[j].date.Month) { Sold[i] = Sold[i] + report[j].quantity; } } } } // find total income double[] Income = new double[monthly.Count]; for (int i = 0; i < monthly.Count; i++) { for (int j = 0; j < report.Count; j++) { if (monthly[i].Year == report[j].date.Year) { if (monthly[i].Month == report[j].date.Month) { Income[i] = Income[i] + report[j].price; } } } } for (int i = 0; i < monthly.Count; i++) { ListViewItem listViewItem = new ListViewItem(new string[] { monthly[i].ToString("M/yyyy"), Sold[i].ToString(), Income[i].ToString("F") }); ReportLV.Items.AddRange(new ListViewItem[] { listViewItem }); } ReportLV.ListViewItemSorter = new ListViewItemComparer(); ReportLV.Sort(); }