Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C# i created a invoice, which has a list view with these columns in this orde

ID: 3802296 • Letter: I

Question

In C# i created a invoice, which has a list view with these columns in this order, Customer, Invoice id, Invoice date, invoice total. When i run the program the info is dsplayed under the wron coulmn heading, Under the customer heading its diplaying the toatal, under the invoice id its dispalying the customer name, under invoice date its showig the id and under the invoice total its showing the date. not sure what i did wrong here is the code,

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
// get invoice method
{
List customerList = CustomerDB.GetCustomers();
List invoiceList = InvoiceDB.GetInvoices();

// store list in varible

var invoices = from Invoice in invoiceList
join customer in customerList
on Invoice.CustomerID equals customer.CustomerID
orderby customer.Name, Invoice.InvoiceTotal descending
select new { customer.Name, Invoice.InvoiceID, Invoice.InvoiceDate, Invoice.InvoiceTotal };

string customerName = "";
int i = 0;

// foreach statment to execute the query

foreach (var invoice in invoices)
{
if (invoice.Name != customerName)
{
lvlnvoices.Items.Add(invoice.Name);
customerName = invoice.Name;
}
else
{
lvlnvoices.Items.Add("");
}
lvlnvoices.Items[i].SubItems.Add(invoice.InvoiceID.ToString());
lvlnvoices.Items[i].SubItems.Add(
Convert.ToDateTime(invoice.InvoiceDate).ToShortDateString());
lvlnvoices.Items[i].SubItems.Add(invoice.InvoiceTotal.ToString("c"));
i += 1;
}
}
} // end of class
} // end of name space

Explanation / Answer

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
// get invoice method
{
List customerList = CustomerDB.GetCustomers();
List invoiceList = InvoiceDB.GetInvoices();

// store list in varible

var invoices = from Invoice in invoiceList
join customer in customerList
on Invoice.CustomerID equals customer.CustomerID
orderby customer.Name, Invoice.InvoiceTotal descending
select new { customer.Name, Invoice.InvoiceID, Invoice.InvoiceDate, Invoice.InvoiceTotal };

string customerName = "";
int i = 0;

// foreach statment to execute the query

foreach (var invoice in invoices)
{
if (invoice.Name != customerName)
{
lvlnvoices.Items.Add(invoice.Name);
customerName = invoice.Name;
}
else
{
lvlnvoices.Items.Add("");
}
lvlnvoices.Items[i].SubItems.Add(invoice.InvoiceID.ToString());
lvlnvoices.Items[i].SubItems.Add(
Convert.ToDateTime(invoice.InvoiceDate).ToShortDateString());
lvlnvoices.Items[i].SubItems.Add(invoice.InvoiceTotal.ToString("c"));
i += 1;
}
}
} // end of class
} // end of name space

code is not clear please eloberate it