//-- Work Order //-- check to see what we entered for quantity if ((myOrder.QtyMade + iQtyChange) > myOrder.QtyRequired) { //-- required quantity exceeded if (MessageBox.Show("The value you entered has exceeded the required quantity. Are you sure this is correct?", "Required Quantity Exceeded", MessageBoxButtons.YesNo) == DialogResult.No) { return; } } //-- check to see which inventory we change if (MessageBox.Show("Are these newly assembled components?", "W.I.P Order #" + myOrder.OrderID.ToString(), MessageBoxButtons.YesNo) == DialogResult.Yes) { //-- this is going into semi-finished //-- I need some way to track how much inventory is in each product, while continuing to do error checking //-- unless I make two passes, one just to check inventory counts, and another to update the inventory //-- levels. //-- we need to loop through each bill of material component and make sure there is stock bool bAllGood = false; //-- we need a separate database connection for the reader (yes, it sucks) SqlConnection RdrConn = new SqlConnection(mySettings.ConnectString); try { //-- open the database connection RdrConn.Open(); SqlDataReader oRdr = myOrder.GetOrderBOM(RdrConn); while (oRdr.Read()) { //-- get the product id/quantity for each BOM component long iBOMProductID = oRdr.GetInt64(0); int iBOMQty = oRdr.GetInt32(1); //-- calculate the total quantity of the piece long iTotalQty = iBOMQty * iQtyChange; //-- get the product info for the BOM component Inventory.clsProductInfo myBOMProduct = new RahnPlastics.Inventory.clsProductInfo(); myBOMProduct.ProductID = iBOMProductID; myBOMProduct.Get(oConn); //-- check the product type to see where we check the inventory level switch (myBOMProduct.ProductTypeID) { case 5: //-- purchase (only has finished quantities) if (myBOMProduct.QtyFinished >= iTotalQty) { bAllGood = true; } else { MessageBox.Show("There isn't enough components to assemble this part. There is not enough inventory for " + myBOMProduct.ProductNo, "W.I.P Order #" + myOrder.OrderID.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } break; case 1: //-- raw (only has semi-manufactured quantities) if (myBOMProduct.QtySemiManufactured >= iTotalQty) { bAllGood = true; } else { MessageBox.Show("There isn't enough components to assemble this part. There is not enough inventory for " + myBOMProduct.ProductNo, "W.I.P Order #" + myOrder.OrderID.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } break; case 2: //-- finished (has semi-finished AND finished quantities) case 3: //-- assembly (has semi-finished AND finished quantities) //-- check to see if we have any finished stock if (myBOMProduct.QtyFinished > 0) { //-- check to see if we have enough finished stock if (myBOMProduct.QtyFinished >= iTotalQty) { //-- we have enough bAllGood = true; long iFinishedQty = iTotalQty; } else { //-- there is not enough, let's look in semi-finished if (myBOMProduct.QtySemiFinished > 0) { //-- check to see if we have enough semi-finished to balance, since we have some finished if (myBOMProduct.QtySemiFinished >= (iTotalQty - myBOMProduct.QtyFinished)) { //-- we have enough bAllGood = true; long iSemiFinishedQty = iTotalQty - myBOMProduct.QtyFinished; long iFinishedQty = iTotalQty; } else { MessageBox.Show("There isn't enough components to assemble this part. There is not enough inventory for " + myBOMProduct.ProductNo, "W.I.P Order #" + myOrder.OrderID.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } else { MessageBox.Show("There isn't enough components to assemble this part. There is not enough inventory for " + myBOMProduct.ProductNo, "W.I.P Order #" + myOrder.OrderID.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } } else { //-- there are none in finished stock, check to see if we have any in semi-finished if (myBOMProduct.QtySemiFinished > 0) { //-- check to see if we have enough semi-finished if (myBOMProduct.QtySemiFinished >= iTotalQty) { //-- we have enough bAllGood = true; long iSemiFinishedQty = iTotalQty; } else { MessageBox.Show("There isn't enough components to assemble this part. There is not enough inventory for " + myBOMProduct.ProductNo, "W.I.P Order #" + myOrder.OrderID.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } else { MessageBox.Show("There isn't enough components to assemble this part. There is not enough inventory for " + myBOMProduct.ProductNo, "W.I.P Order #" + myOrder.OrderID.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } break; } //-- if all good, adjust inventory levels MessageBox.Show("We must have enough"); } //-- close up the reader oRdr.Close(); } catch (Exception ex) { MessageBox.Show("Database error has occurred: " + ex.ToString()); return; } finally { //-- close up the reader connection RdrConn.Close(); } } else { //-- this is going into finished //-- inventory must be moved from semi-finished to finished //-- make sure we have the inventory from semi-finished if (myProduct.QtySemiFinished >= iQtyChange) { myProduct.QtySemiFinished -= iQtyChange; myProduct.QtyFinished += iQtyChange; } else { //-- not enough semi-finished inventory MessageBox.Show("You do not have enough inventory in semi-finished to complete this transaction. Please check your inventory count.", "W.I.P Order #" + myOrder.OrderID.ToString(),MessageBoxButtons.OK,MessageBoxIcon.Warning); return; } }