Ejemplo n.º 1
0
        /*  Adds item data to orderInfo list and displays it in order summary
         *  ***************************************/
        private void addItemBtn_Click(object sender, EventArgs e)
        {
            // Get item descipriton and determine if itemNumber exists in the database
            string materialSearch = "SELECT description FROM Materials WHERE itemID = '" + itemNumber.Text + "' LIMIT 1";
            string result         = dbconn.getString(materialSearch);

            // Hanle no matching item found in database
            if (result == null)
            {
                MessageBox.Show("Item number doesn't exist. Please try another item number.", "Invalid Item", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                itemValidityMessage.Text      = "Invalid Item Number";
                itemValidityMessage.Visible   = true;
                itemValidityMessage.ForeColor = errorColor;
                itemQuantity.Clear();
                itemNumber.Clear();
                itemNumber.Select();
            }
            else
            {
                itemValidityMessage.Visible = false;            // Hide invalid item number message

                // Retrieve item description from database
                string itemDescription = result;

                // Displays item in summary box and increments itemCount
                try
                {
                    if (Convert.ToInt32(itemQuantity.Text) < 1 || Convert.ToInt32(itemQuantity.Text) > 100)
                    {
                        MessageBox.Show("Please enter an item quantity between 1 and 100.", "Invalid Quantity", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else
                    {
                        // Add new order item to list
                        orderInfo.Add(new TempOrderInfo()
                        {
                            itemNumber  = Convert.ToInt32(itemNumber.Text),
                            jobCode     = Convert.ToInt32(jobCode.Text),
                            description = itemDescription,
                            quantity    = Convert.ToInt32(itemQuantity.Text)
                        });

                        // Add item to data grid view
                        TempOrderInfo lastEntry = orderInfo.Last();
                        orderSummaryTable.Rows.Add(lastEntry.itemNumber, lastEntry.description, lastEntry.quantity);

                        submitOrderBtn.Enabled = true;
                        cancelBtn.Enabled      = true;
                        itemNumber.Clear();
                        itemQuantity.Clear();
                        itemNumber.Select();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
        private void btnAddItem_Click(object sender, EventArgs e)
        {
            //Verify item and quantity are available in database and required rank
            try
            {
                string quantityReq     = txtQuantity.Text;
                int    currentQuantity = db.getInt("SELECT available FROM Equipment WHERE equipmentID =" + txtScanItem.Text + ";");

                int newQuantity = currentQuantity - Convert.ToInt32(quantityReq);
                if (newQuantity < 0)
                {
                    lblInformation.Text      = "Not enough inventory to supply this order. \n\nContact Warehouse Personel or Inventory Management.";
                    lblInformation.ForeColor = Color.Red;
                    return;
                }

                string eqDescription = db.getString("SELECT description FROM Equipment WHERE equipmentID ='" + txtScanItem.Text + "';");


                string query = "SELECT equipmentID FROM Equipment WHERE (equipmentID = '"
                               + txtScanItem.Text + "' AND equipmentStatus ='In Stock' AND requiredRank <='"
                               + currentUser.getRank() + "' AND available>='" + quantityReq + "');";


                //If item is found:
                if (db.getBool(query, true))
                {
                    lblInformation.Text      = "Item number: [" + txtScanItem.Text + "]\n\nQuantity: [" + quantityReq + "] successfully added.";
                    lblInformation.ForeColor = Color.Blue;

                    // Add new order item to list
                    orderInfo.Add(new TempOrderInfo()
                    {
                        itemNumber  = Convert.ToInt32(txtScanItem.Text),
                        jobCode     = Convert.ToInt32(txtJobCode.Text),
                        description = eqDescription,
                        quantity    = Convert.ToInt32(txtQuantity.Text)
                    });

                    // Add item to data grid view
                    TempOrderInfo lastEntry = orderInfo.Last();
                    dt.Rows.Add(lastEntry.itemNumber, lastEntry.description, lastEntry.quantity);
                }
                else
                {
                    lblInformation.Text      = "Unable to add item. \nThis error will occur if the item is not in stock or does not exist. \n\n\nStock amount: " + currentQuantity + ". \n\n\nContact warehouse management if this problem persists.";
                    lblInformation.ForeColor = Color.Red;
                }

                //Add item to datagridview list to be put in pending


                //Select field

                txtScanItem.Clear();
                txtScanItem.Select();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            count++;
        }