private static void SeedInvoices(int num) { int invoiceID = 1; //make invoices for 5 customers for (int i = 1; i < num; i++) { //make 5 invoice per customer for (int j = 1; j < 5; j++) { InvoiceDatabase.AddInvoice(invoiceID, i, "order" + j, "invoice" + j); //make num items in each invoice for (int m = 1; m < num; m++) { InvoiceContentsDatabase.AddInvoiceContent(invoiceID, "A" + m, m, "notes"); } Invoice inv = new Invoice(invoiceID); inv.SaveToExcel(); invoiceID++; } } }
private void OkButton_Click(object sender, EventArgs e) { bool valid = true; for (int j = 0; j < i; j++) { if (this.panel1.Controls["qty" + j].Text.Length == 0 & this.panel1.Controls["itemNumber" + j].Text.Length != 0) { valid = false; this.panel1.Controls["qty" + j].BackColor = Color.Red; } if (this.panel1.Controls["qty" + j].Text.Length != 0 & this.panel1.Controls["itemNumber" + j].Text.Length == 0) { valid = false; this.panel1.Controls["itemNumber" + j].BackColor = Color.Red; } if (this.panel1.Controls["qty" + j].Text.Length == 1 && this.panel1.Controls["qty" + j].Text == "-") { valid = false; this.panel1.Controls["qty" + j].BackColor = Color.Red; } } if (valid == true) { var confirmResult = MessageBox.Show("Are you sure this invoice is complete?", "Confirm Completion!!", MessageBoxButtons.YesNo); if (confirmResult == DialogResult.Yes) { Customer cust = CustomerDatabase.SearchCustomersByID(customerID); int invoiceID; invoiceID = InvoiceDatabase.AddInvoice(customerID, this.Controls["purchaseOrder"].Text, ""); for (int j = 0; j < i; j++) { if (this.panel1.Controls["qty" + j].Text.Length != 0) { String itemNo = this.panel1.Controls["itemNumber" + j].Text; int qty = Int32.Parse(this.panel1.Controls["qty" + j].Text); String notes = this.panel1.Controls["specialNotes" + j].Text; InvoiceContentsDatabase.AddInvoiceContent(invoiceID, itemNo, qty, notes); } } Invoice invoice = new Invoice(invoiceID); invoice.SaveToExcel(); finished = true; this.Close(); } else { // If 'No', do something here. } } }