Beispiel #1
0
        // Submitting retrieved amount
        protected void BtnCumulativeSubmit_Click(object sender, EventArgs e)
        {
            // Specify all our attrs that we need
            string tempStr = "";

            // Retrieving values from each cell in the gridviews
            foreach (GridViewRow row1 in GridViewMainList.Rows)
            {
                // Retrieving the itemID of this specific row
                Label LblItemID1 = (Label)row1.FindControl("LblItemID1");

                // Finding the nested GridView
                GridView GridViewSubList = (GridView)row1.FindControl("GridViewSubList");

                // Retrieving the main values from the nested GridView
                foreach (GridViewRow row2 in GridViewSubList.Rows)
                {
                    Label   LblReqID       = (Label)row2.FindControl("LblReqID");
                    Label   LblReqDetailID = (Label)row2.FindControl("LblReqDetailID");
                    Label   LblDeptID      = (Label)row2.FindControl("LblDeptID");
                    Label   LblQtyNeeded   = (Label)row2.FindControl("LblQtyNeeded");
                    Label   LblIsOverride  = (Label)row2.FindControl("LblIsOverride");
                    TextBox TbxActualQty   = (TextBox)row2.FindControl("TbxActualQty");

                    if (TbxActualQty.Text == "" || string.IsNullOrWhiteSpace(TbxActualQty.Text))          // SERVER-SIDE VALIDATION
                    {
                        tempStr += "Item " + LblItemID1.Text + " from department " + LblDeptID.Text + " is not processed.\n\n";
                        break;             // If any error, the entire row and subsequent rows will be gone.
                    }
                    else
                    {
                        int actQty = 0;

                        // Checking if input entered is int or not
                        if (Int32.TryParse(TbxActualQty.Text.ToString(), out actQty))
                        {
                            if (actQty == 0)
                            {
                                tempStr += "Item " + LblItemID1.Text + " from department " + LblDeptID.Text + " will not be processed.\n\n";
                            }
                            else
                            {
                                // Processing our inventory withdrawal process
                                string result = InventoryLogic.CreateNewInventoryRetrievalEntry(Convert.ToInt32(LblReqID.Text.ToString()), Convert.ToInt32(LblReqDetailID.Text.ToString()), LblItemID1.Text.ToString(),
                                                                                                LblDeptID.Text.ToString(), Convert.ToInt32(LblQtyNeeded.Text), Convert.ToInt32(TbxActualQty.Text), Boolean.Parse(LblIsOverride.Text));

                                // Displaying its result
                                tempStr += result + "\n\n";
                            }
                        }
                        else
                        {
                            tempStr += "Invalid input for item code, " + LblItemID1.Text + ". Please try again.\n\n";
                        }
                    }
                }
            }

            // Storing message as a session state and refreshing the page
            Session["RetrievalListMessage"] = tempStr;
            Response.Redirect("~/StoreClerk/RetrievalList.aspx");
        }
Beispiel #2
0
        // Creating new entry
        public string SubmitInventoryRetrieval(List <WCF_TempInventoryRetrieval> tempList, string token)
        {
            //Check if user is authorizated to use this method. If is not authorized, it will return a json with -1 in the primary key
            if (!IsAuthanticateUser(token))
            {
                List <WCF_TempInventoryRetrieval> wcf_UnAuthObj = new List <WCF_TempInventoryRetrieval>();
                WCF_TempInventoryRetrieval        wcfUnAuth     = new WCF_TempInventoryRetrieval();
                wcfUnAuth.RequestID = -1;
                wcf_UnAuthObj.Add(wcfUnAuth);
                return("Invalid user.");
            }

            bool anyErrors1 = false;
            bool anyErrors2 = true;

            // Checking against existing quantity in the store currently
            string itemID            = "";
            int    totalRetrievedQty = 0;

            foreach (var item in tempList)
            {
                itemID             = item.ItemID;
                totalRetrievedQty += item.ActualQty;
            }
            int currentQty = InventoryLogic.GetQuantity(itemID);

            if (totalRetrievedQty > currentQty)
            {
                anyErrors1 = true;
            }

            bool isEnough = true;

            // If still no errors, will perform more checks till an error is found.
            if (!anyErrors1)
            {
                foreach (var item in tempList)
                {
                    InventoryCatalogue ic = InventoryLogic.FindItemByItemID(itemID);

                    //Check if there is insufficient quantity in the inventory
                    if (ic.UnitsInStock < item.RequestedQty || ic.UnitsInStock < item.RequestedQty)
                    {
                        isEnough = false;

                        if (!isEnough && ic.UnitsInStock < item.RequestedQty)
                        {
                            anyErrors1 = true;
                        }
                    }

                    //If inventory is not enough and isOverride is true
                    if (item.IsOverride)
                    {
                        isEnough   = false;
                        anyErrors2 = false;
                    }

                    //Check if user is withdrawing more than requested
                    if (item.RequestedQty < item.ActualQty)
                    {
                        anyErrors1 = true;
                    }

                    //Check if user is withdrawing less than requested despite having enough in the inventory
                    if (isEnough && item.RequestedQty > item.ActualQty && !item.IsOverride)
                    {
                        anyErrors1 = true;
                    }


                    if (anyErrors1)
                    {
                        break;
                    }
                }
            }

            // If there is a single error, the process will terminate without updating any of the entries
            if (anyErrors1 && anyErrors2)
            {
                return("Failure.");
            }
            else
            {
                foreach (WCF_TempInventoryRetrieval item in tempList)
                {
                    string str = InventoryLogic.CreateNewInventoryRetrievalEntry(item.RequestID, item.RequestDetailID, item.ItemID, item.DepartmentID, item.RequestedQty, item.ActualQty, item.IsOverride);
                }

                return("Success.");
            }
        }