// ------------------------------------------------------------------------- // LISTBOXES // Order List private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { aInfo tRec = (aInfo)listBox1.SelectedItem; // if not null if (listBox1.SelectedItem != null) { if (listBox1.Items.Count > 0) { // clear list box 2 listBox2.Items.Clear(); using (var context = new manufacturerEntities1()) { // use VIEW var query = from st in context.vInvoiceLineItemsAndInventories where st.invoiceID == tRec.i_id select st; foreach (vInvoiceLineItemsAndInventory ivv in query) { aInfo tempB = new aInfo() { i_id = ivv.invoiceID, is_id = ivv.invoiceSequence, name = ivv.itemName, qty = ivv.quantityOfItem, returnVal = ivv.itemName + "\t Qty: " + ivv.quantityOfItem + "\t Unit Price: $" + ivv.invoiceLineItemPrice + "\t Status: " + ivv.orderStatus }; listBox2.Items.Add(tempB); } } } else { using (var context = new manufacturerEntities1()) { // use VIEW var query = from st in context.vInvoiceLineItemsAndInventories where st.invoiceID == tRec.i_id select st; foreach (vInvoiceLineItemsAndInventory ivv in query) { aInfo tempB = new aInfo() { i_id = ivv.invoiceID, is_id = ivv.invoiceSequence, name = ivv.itemName, qty = ivv.quantityOfItem, returnVal = ivv.itemName + "\t Qty: " + ivv.quantityOfItem + "\t Unit Price: $" + ivv.invoiceLineItemPrice + "\t Status: " + ivv.orderStatus }; listBox2.Items.Add(tempB); } } } } }
// Update Button private void button3_Click(object sender, EventArgs e) { // make sure only ints are inputed int parsedValue; if (!int.TryParse(textBox4.Text, out parsedValue)) { MessageBox.Show("This is a number only field"); return; } // get the selected item in this list box. aInfo t3Rec = (aInfo)listBox2.SelectedItem; using (var context = new manufacturerEntities1()) { // Update Quantity Stored Procedure var updtQty = context.updtQty(t3Rec.i_id, t3Rec.is_id, int.Parse(textBox4.Text)); // Update Total Order Amount Stored Procedure var updtTotal = context.updtOrderTotal(t3Rec.i_id); } // refresh list box 2 items aInfo tRec = (aInfo)listBox1.SelectedItem; // if not null if (listBox1.SelectedItem != null) { if (listBox1.Items.Count > 0) { // clear list box 2 listBox2.Items.Clear(); using (var context = new manufacturerEntities1()) { // use VIEW var query = from st in context.vInvoiceLineItemsAndInventories where st.invoiceID == tRec.i_id select st; foreach (vInvoiceLineItemsAndInventory ivv in query) { aInfo tempB = new aInfo() { i_id = ivv.invoiceID, is_id = ivv.invoiceSequence, name = ivv.itemName, qty = ivv.quantityOfItem, returnVal = ivv.itemName + "\t Qty: " + ivv.quantityOfItem + "\t Unit Price: $" + ivv.invoiceLineItemPrice + "\t Status: " + ivv.orderStatus }; listBox2.Items.Add(tempB); } } } else { using (var context = new manufacturerEntities1()) { // use VIEW var query = from st in context.vInvoiceLineItemsAndInventories where st.invoiceID == tRec.i_id select st; foreach (vInvoiceLineItemsAndInventory ivv in query) { aInfo tempB = new aInfo() { i_id = ivv.invoiceID, is_id = ivv.invoiceSequence, name = ivv.itemName, qty = ivv.quantityOfItem, returnVal = ivv.itemName + "\t Qty: " + ivv.quantityOfItem + "\t Unit Price: $" + ivv.invoiceLineItemPrice + "\t Status: " + ivv.orderStatus }; listBox2.Items.Add(tempB); } } } } // wait till user select listbox again. textBox4.Enabled = false; //listBox1.Enabled = false; // then display the new search order. using (var context = new manufacturerEntities1()) { var query = from st in context.invoices where st.invoiceID == tRec.i_id select st; foreach (invoice iv in query) { aInfo tempA = new aInfo() { i_id = iv.invoiceID, totalPrice = iv.orderTotalPrice, returnVal = "Invoice ID: " + iv.invoiceID + "\t Customer ID: " + iv.customerID + "\t Total Order Price: $" + iv.orderTotalPrice }; label12.Text = iv.orderTotalPrice.ToString(); } } }
// Search Customer ID private void button2_Click(object sender, EventArgs e) { // make sure only ints are inputed int parsedValue; if (!int.TryParse(textBox2.Text, out parsedValue)) { MessageBox.Show("This is a number only field"); return; } // parse int string tb2 = textBox2.Text; int intVal2 = int.Parse(tb2); if (listBox1.Items.Count > 0) { // clear list box 1 listBox1.Items.Clear(); // clear list box 2 listBox2.Items.Clear(); // then display the new search order. using (var context = new manufacturerEntities1()) { var query = from st in context.invoices where st.customerID == intVal2 select st; foreach (invoice iv in query) { aInfo tempA = new aInfo() { i_id = iv.invoiceID, returnVal = "Invoice ID: " + iv.invoiceID + "\t Customer ID: " + iv.customerID + "\t Total Order Price: $" + iv.orderTotalPrice }; listBox1.Items.Add(tempA); } } } else { using (var context = new manufacturerEntities1()) { var query = from st in context.invoices where st.customerID == intVal2 select st; foreach (invoice iv in query) { aInfo tempA = new aInfo() { i_id = iv.invoiceID, returnVal = "Invoice ID: " + iv.invoiceID + "\t Customer ID: " + iv.customerID + "\t Total Order Price: $" + iv.orderTotalPrice }; listBox1.Items.Add(tempA); } } } }