private static Sale MapSaleDapperQuery(IDictionary <int, Sale> saleDictionary, Sale sale,
                                               ItemSale itemSale, VinylDisc vinylDisc)
        {
            if (!saleDictionary.TryGetValue(sale.SaleId, out var saleEntry))
            {
                saleEntry = sale;
                saleDictionary.Add(saleEntry.SaleId, saleEntry);
            }

            itemSale.SetVinylDisc(vinylDisc);
            saleEntry.AddItemSale(itemSale);

            return(saleEntry);
        }
Пример #2
0
        public async Task <IActionResult> BuyCart()
        {
            if (HttpContext.Session.GetString("cartID") != null)
            {
                var cartContentID = HttpContext.Session.GetString("cartID");
                var cartListID    = new List <String>(cartContentID.Split(','));

                var cartContentAMT = HttpContext.Session.GetString("cartAMT");
                var cartListAMT    = new List <String>(cartContentAMT.Split(','));

                var itemList = new List <Item>();

                foreach (var item in cartListID)
                {
                    var temp = Int32.Parse(item);
                    itemList.Add(_context.Items.Find(temp));
                }

                var transaction = new Transaction();
                await _context.AddAsync(transaction);

                await _context.SaveChangesAsync();

                var i = 0;
                while (i < cartListID.Count())
                {
                    var itemSale = new ItemSale
                    {
                        item          = itemList[i],
                        transactionID = transaction.transactionID,
                        quantity      = Int32.Parse(cartListAMT[i])
                    };

                    var item = _context.Items.Find(itemList[i].itemID);
                    item.Quantity = item.Quantity - itemSale.quantity;
                    _context.Items.Update(item);

                    await _context.AddAsync(itemSale);

                    await _context.SaveChangesAsync();

                    i++;
                }

                double costTotal = 0;

                foreach (var item in transaction.sales)
                {
                    costTotal = costTotal + (item.quantity * item.item.price);
                }

                transaction.price = costTotal;

                var user = await _userManager.GetUserAsync(User);

                transaction.buyer = user.UserName;

                _context.Update(transaction);
                await _context.SaveChangesAsync();

                HttpContext.Session.Remove("cartID");
                HttpContext.Session.Remove("cartAMT");
            }

            return(RedirectToAction("UserHome"));
        }
Пример #3
0
        public bool GetBuyAnchor(int buyIdx, out string buyAnchor)
        {
            Transaction Trans = null;

            buyAnchor = "<button style=\"margin-left:6px\" id=\"DelLink" + buyIdx + "\">x</button>";

            switch (buyIdx)
            {
            case 1:
                if (InventoryItem.Buy1Id.HasValue)
                {
                    Trans = _context.Transaction.Find(InventoryItem.Buy1Id);
                    if ((Trans == null) || (Trans.Link.Length < 10))
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
                break;

            case 2:
                if (InventoryItem.Buy2Id.HasValue)
                {
                    Trans = _context.Transaction.Find(InventoryItem.Buy2Id);
                    if ((Trans == null) || (Trans.Link.Length < 10))
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
                break;

            case 3:
                if (InventoryItem.Buy3Id.HasValue)
                {
                    Trans = _context.Transaction.Find(InventoryItem.Buy3Id);
                    if ((Trans == null) || (Trans.Link.Length < 10))
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
                break;

            default:
                return(false);
            }

            buyAnchor = "<a href=\"" + Trans.Link + "\" id=\"Anc" + buyIdx + "\" BuyId=\"" + Trans.Id + "\">" +
                        ((Trans.Memo.Length > 1) ? "Buy from " + ItemSale.ResolveVendor(Trans.Memo) : "Store #" + buyIdx) + "</a><button style=\"margin-left:6px\" id=\"DelLink" + buyIdx + "\">x</button>";
            return(true);
        }
Пример #4
0
        public JsonResult OnGetUrlPrice()
        {
            var rawQS = Uri.UnescapeDataString(Request.QueryString.ToString());
            var idx   = rawQS.IndexOf('{');

            if (idx == -1)
            {
                return(new JsonResult("ERROR~:No Parameters"));
            }
            var jsonQS = rawQS.Substring(idx);
            Dictionary <string, string> setParam = JsonConvert.DeserializeObject <Dictionary <string, string> >(jsonQS);

            if (!setParam.TryGetValue("id", out string idStr) || !setParam.TryGetValue("link", out string url) || !setParam.TryGetValue("host", out string host))
            {
                return(new JsonResult(""));
            }

            var lhost = CCommon.UnencodeQuotes(host).ToLower().Trim();

            var pageContents = ItemSale.GetPageContent(url).Result;

            if (pageContents.Length < 50)
            {
                return(new JsonResult(""));
            }

            double price = 0;

            //************************
            // AMAZON
            //************************
            if (lhost.Contains(" amazon") || (lhost == "amazon"))
            {
                var priceIdx = pageContents.IndexOf("id=\"attach-base-product-price\" value=\"");
                if (priceIdx != -1)
                {
                    var priceStr = pageContents.Substring(priceIdx + 38, 15);
                    var endIdx   = priceStr.IndexOf("\"");
                    if (endIdx != -1)
                    {
                        priceStr = priceStr.Substring(0, endIdx);
                        if (!double.TryParse(priceStr, out price))
                        {
                            price = 0;
                        }
                    }
                }
                else
                {
                    // "priceAmount":10.94,
                    priceIdx = pageContents.IndexOf("\"priceAmount\":");
                    if (priceIdx != -1)
                    {
                        var priceStr = pageContents.Substring(priceIdx + 14, 15);
                        var endIdx   = priceStr.IndexOf(",");
                        if (endIdx != -1)
                        {
                            priceStr = priceStr.Substring(0, endIdx);
                            if (!double.TryParse(priceStr, out price))
                            {
                                price = 0;
                            }
                        }
                    }
                    else
                    {
                        priceIdx = pageContents.IndexOf("id=\"price_inside_buybox\"");
                        if (priceIdx != -1)
                        {
                            //<span id="price_inside_buybox" class="a-size-medium a-color-price">
                            //$64.31
                            //</span>
                            var priceStr = pageContents.Substring(priceIdx + 24, 100);
                            var dollIdx  = priceStr.IndexOf("$");
                            if (dollIdx != -1)
                            {
                                var dollStr = priceStr.Substring(dollIdx + 1, 50);
                                var endDel  = dollStr.IndexOf("<");
                                if (endDel != -1)
                                {
                                    priceStr = dollStr.Substring(0, endDel).Trim();
                                    if (!double.TryParse(priceStr, out price))
                                    {
                                        price = 0;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            //*********************
            // WALMART
            //*********************
            else if (ItemSale.IsVendor(lhost, "walmart"))
            {
                var priceIdx = pageContents.IndexOf("<span class=\"price-characteristic\" itemprop=\"price\" content=\"");
                if (priceIdx != -1)
                {
                    var priceStr = pageContents.Substring(priceIdx + 61, 15);
                    var endIdx   = priceStr.IndexOf("\"");
                    if (endIdx != -1)
                    {
                        priceStr = priceStr.Substring(0, endIdx);
                        if (!double.TryParse(priceStr, out price))
                        {
                            price = 0;
                        }
                    }
                }
                else
                {
                    priceIdx = pageContents.IndexOf("\"price\":");
                    if (priceIdx != -1)
                    {
                        var priceStr = pageContents.Substring(priceIdx + 8, 15);
                        var endIdx   = priceStr.IndexOf(",");
                        if (endIdx != -1)
                        {
                            priceStr = priceStr.Substring(0, endIdx);
                            if (!double.TryParse(priceStr, out price))
                            {
                                price = 0;
                            }
                        }
                    }
                }
            }
            else if (ItemSale.IsVendor(lhost, "bj's"))
            {
                var priceIdx = pageContents.IndexOf(";offerPrice&q;:");
                if (priceIdx != -1)
                {
                    var priceStr = pageContents.Substring(priceIdx + 15, 15);
                    var endIdx   = priceStr.IndexOf(",");
                    if (endIdx != -1)
                    {
                        priceStr = priceStr.Substring(0, endIdx);
                        if (!double.TryParse(priceStr, out price))
                        {
                            price = 0;
                        }
                    }
                }
            }
            else if (ItemSale.IsVendor(lhost, "home depot"))
            {
                var priceIdx = pageContents.IndexOf("\"priceCurrency\":\"USD\",\"price\":");
                if (priceIdx != -1)
                {
                    var priceStr = pageContents.Substring(priceIdx + 30, 15);
                    var endIdx   = priceStr.IndexOf(",");
                    if (endIdx != -1)
                    {
                        priceStr = priceStr.Substring(0, endIdx);
                        if (!double.TryParse(priceStr, out price))
                        {
                            price = 0;
                        }
                    }
                }
            }
            else if (ItemSale.IsVendor(lhost, "webstaurantstore"))
            {
                var priceIdx = pageContents.IndexOf("<meta property=\"og:price:amount\" content=\"");
                if (priceIdx != -1)
                {
                    var priceStr = pageContents.Substring(priceIdx + 42, 15);
                    var endIdx   = priceStr.IndexOf("\"");
                    if (endIdx != -1)
                    {
                        priceStr = priceStr.Substring(0, endIdx);
                        if (!double.TryParse(priceStr, out price))
                        {
                            price = 0;
                        }
                    }
                }
            }
            else if (ItemSale.IsVendor(lhost, "lowes"))
            {
                var priceIdx = pageContents.IndexOf(",\"price\":");
                if (priceIdx != -1)
                {
                    var priceStr = pageContents.Substring(priceIdx + 9, 15);
                    var endIdx   = priceStr.IndexOf(",");
                    if (endIdx != -1)
                    {
                        priceStr = priceStr.Substring(0, endIdx);
                        if (!double.TryParse(priceStr, out price))
                        {
                            price = 0;
                        }
                    }
                }
            }
            else if (ItemSale.IsVendor(lhost, "filtersfast.com"))
            {
                var priceIdx = pageContents.IndexOf("value:");
                if (priceIdx != -1)
                {
                    var priceStr = pageContents.Substring(priceIdx + 6, 15);
                    var endIdx   = priceStr.IndexOf(",");
                    if (endIdx != -1)
                    {
                        priceStr = priceStr.Substring(0, endIdx);
                        if (!double.TryParse(priceStr, out price))
                        {
                            price = 0;
                        }
                    }
                }
            }
            // Costco
            else if (ItemSale.IsVendor(lhost, "costco"))
            {
                var priceIdx = pageContents.IndexOf("\"product:price:amount\" content=\"");
                if (priceIdx != -1)
                {
                    var priceStr = pageContents.Substring(priceIdx + 32, 15);
                    var endIdx   = priceStr.IndexOf("\"");
                    if (endIdx != -1)
                    {
                        priceStr = priceStr.Substring(0, endIdx);
                        if (!double.TryParse(priceStr, out price))
                        {
                            price = 0;
                        }
                    }
                }
            }
            // USRS
            else if (ItemSale.IsVendor(lhost, "USRS"))
            {
                var priceIdx = pageContents.IndexOf("\"Offer\",\"price\":\"");
                if (priceIdx != -1)
                {
                    var priceStr = pageContents.Substring(priceIdx + 17, 15);
                    var endIdx   = priceStr.IndexOf("\"");
                    if (endIdx != -1)
                    {
                        priceStr = priceStr.Substring(0, endIdx);
                        if (!double.TryParse(priceStr, out price))
                        {
                            price = 0;
                        }
                    }
                }
            }
            else if (ItemSale.IsVendor(lhost, "Salamone Supplies"))
            {
                var priceIdx = pageContents.IndexOf("\"price\":\"");
                if (priceIdx != -1)
                {
                    var priceStr = pageContents.Substring(priceIdx + 9, 15);
                    var endIdx   = priceStr.IndexOf("\"");
                    if (endIdx != -1)
                    {
                        priceStr = priceStr.Substring(0, endIdx);
                        if (!double.TryParse(priceStr, out price))
                        {
                            price = 0;
                        }
                    }
                }
            }
            else if (ItemSale.IsVendor(lhost, "target"))
            {
                string apiKey;
                var    apiKeyIdx = pageContents.IndexOf("\"apiKey\":\"");
                apiKey = pageContents.Substring(apiKeyIdx + 10, 50);
                if (apiKeyIdx != -1)
                {
                    var endIdx = apiKey.IndexOf("\"");
                    apiKey = apiKey.Substring(0, endIdx);
                }

                string[] urlParts = url.Split("/");
                string   tcinKey  = urlParts[(urlParts.Length < 7) ? (urlParts.Length - 1) : 6].Substring(2);
                var      attrIdxP = tcinKey.IndexOf("#");
                if (attrIdxP == -1)
                {
                    attrIdxP = 1000;
                }
                var attrIdxQ = tcinKey.IndexOf("?");
                if (attrIdxQ == -1)
                {
                    attrIdxQ = 1000;
                }
                var attrIdx = Math.Min(attrIdxP, attrIdxQ);
                if ((attrIdx != -1) && (attrIdx <= 15))
                {
                    tcinKey = tcinKey.Substring(0, attrIdx);
                }
                else
                {
                    tcinKey = tcinKey.Substring(0, 8);
                }

                //"https://redsky.target.com/redsky_aggregations/v1/web/pdp_client_v1?key=ff457966e64d5e877fdbad070f276d18ecec4a01&tcin=13276131&store_id=1528&pricing_store_id=1528&has_financing_options=true&visitor_id=017BA97BC6FA02019E64C97AB60EA049&has_size_context=true&latitude=41.540&longitude=-73.430&state=CT&zip=06776";
                string bUrl = "https://redsky.target.com/redsky_aggregations/v1/web/pdp_client_v1?key=" + apiKey + "&tcin=" + tcinKey + "&store_id=1528&pricing_store_id=1528&has_financing_options=true&visitor_id=017BA97BC6FA02019E64C97AB60EA049&has_size_context=true&latitude=41.540&longitude=-73.430&state=CT&zip=06776";

                var subPageStr = ItemSale.GetPageContent(bUrl).Result;
                var priceIdx   = subPageStr.IndexOf("\"current_retail\":");
                if (priceIdx != -1)
                {
                    var priceStr = subPageStr.Substring(priceIdx + 17, 15);
                    var endIdx   = priceStr.IndexOf(",");
                    if (endIdx != -1)
                    {
                        priceStr = priceStr.Substring(0, endIdx);
                        if (!double.TryParse(priceStr, out price))
                        {
                            price = 0;
                        }
                    }
                }
            }

            return(new JsonResult((price != 0) ? (idStr + "; $" + price.ToString("#.00", CultureInfo.InvariantCulture)) : pageContents.Length.ToString()));
        }
Пример #5
0
        public bool ProcessInfoCode(IPosTransaction posTransaction, decimal quantity, decimal amount, string refRelation, string refRelation2, string refRelation3,
                                    InfoCodeTableRefType tableRefId, string linkedInfoCodeId, IInfoCodeLineItem orgInfoCode, InfoCodeType infoCodeType)
        {
            RetailTransaction      retailTransaction      = posTransaction as RetailTransaction;
            TenderCountTransaction tenderCountTransaction = posTransaction as TenderCountTransaction;

            // Other possible transaction types at this point include CustomerPayment

            if (refRelation == null)
            {
                refRelation = string.Empty;
            }

            if (refRelation2 == null)
            {
                refRelation2 = string.Empty;
            }

            if (refRelation3 == null)
            {
                refRelation3 = string.Empty;
            }

            //Infocode
            IInfoCodeSystem infoCodeSystem = this.Application.BusinessLogic.InfoCodeSystem;

            IInfoCodeLineItem[] infoCodes = new IInfoCodeLineItem[0];

            if (!string.IsNullOrEmpty(linkedInfoCodeId))
            {
                infoCodes = infoCodeSystem.GetInfocodes(linkedInfoCodeId);
            }
            else if (tableRefId == InfoCodeTableRefType.FunctionalityProfile)
            {
                infoCodes    = infoCodeSystem.GetInfocodes(refRelation2);
                refRelation2 = string.Empty;
            }
            else if (tableRefId == InfoCodeTableRefType.PreItem)
            {
                // Pre item is just a table ref id of item, but handled during different processing
                infoCodes = infoCodeSystem.GetInfocodes(refRelation, refRelation2, refRelation3, InfoCodeTableRefType.Item);
            }
            else
            {
                infoCodes = infoCodeSystem.GetInfocodes(refRelation, refRelation2, refRelation3, tableRefId);
            }

            foreach (InfoCodeLineItem infoCode in infoCodes)
            {
                if (infoCode.InfocodeId == null)
                {
                    return(false);
                }                                                  //If no infocode is found

                // Process age limit info codes as pre item.  I.e. stop processing on this info code if it is pre item
                // and not of type age limit.
                // Low impact fix that should be reevaluated if any info code other than age limit is ever added
                // pre item.  Using continue because indentation of if/else sequence already too much.
                if (((tableRefId == InfoCodeTableRefType.PreItem) && (infoCode.InputType != InfoCodeInputType.AgeLimit)))
                {
                    continue;
                }

                //If bug in data, fixes division by zero
                if (infoCode.RandomFactor == 0)
                {
                    infoCode.RandomFactor = 100;
                }

                infoCode.OriginType   = infoCodeType;
                infoCode.RefRelation  = refRelation;
                infoCode.RefRelation2 = refRelation2;
                infoCode.RefRelation3 = refRelation3;
                switch (infoCode.OriginType)
                {
                case InfoCodeType.Header:
                    infoCode.Amount = amount;
                    break;

                case InfoCodeType.Sales:
                    infoCode.Amount = (amount * -1);
                    break;

                case InfoCodeType.Payment:
                    infoCode.Amount = amount;
                    break;

                case InfoCodeType.IncomeExpense:
                    infoCode.Amount = amount;
                    break;
                }

                int    randomFactor = (int)(100 / infoCode.RandomFactor); //infoCode.RandomFactor = 100 means ask 100% for a infocode
                Random random       = new Random();
                int    randomNumber = random.Next(randomFactor);          //Creates numbers from 0 to randomFactor-1
                //Only get the infocode if randomfactor is set to zero or generated random number is the sama as the randomfactor-1
                if (infoCode.RandomFactor == 100 || randomNumber == (randomFactor - 1))
                {
                    Boolean infoCodeNeeded = true;
                    if (infoCode.OncePerTransaction)
                    {
                        if (tenderCountTransaction != null)
                        {
                            infoCodeNeeded = tenderCountTransaction.InfoCodeNeeded(infoCode.InfocodeId);
                        }
                        else
                        {
                            infoCodeNeeded = retailTransaction.InfoCodeNeeded(infoCode.InfocodeId);
                        }
                    }

                    if (infoCodeNeeded)
                    {
                        // If the required type is negative but the quantity is positive, do not continue
                        if (infoCode.InputRequiredType == InfoCodeInputRequiredType.Negative && quantity > 0)
                        {
                            infoCodeNeeded = false;
                        }

                        // If the required type is positive but the quantity is negative, do not continue
                        if (infoCode.InputRequiredType == InfoCodeInputRequiredType.Positive && quantity < 0)
                        {
                            infoCodeNeeded = false;
                        }
                    }
                    // If there is some infocodeID existing, and infocod is needed
                    if (infoCode.InfocodeId != null && infoCodeNeeded == true)
                    {
                        #region Text and General
                        if (infoCode.InputType == InfoCodeInputType.Text || infoCode.InputType == InfoCodeInputType.General)
                        {
                            Boolean inputValid = true;
                            bool    abort      = false;
                            // Get a infocode text
                            do
                            {
                                inputValid = true;

                                InputConfirmation inputConfirmation = new InputConfirmation()
                                {
                                    MaxLength  = MaxInfocodeInformationLengh,
                                    PromptText = infoCode.Prompt,
                                };

                                InteractionRequestedEventArgs request = new InteractionRequestedEventArgs(inputConfirmation, () =>
                                {
                                    if (inputConfirmation.Confirmed)
                                    {
                                        if (string.IsNullOrEmpty(inputConfirmation.EnteredText))
                                        {
                                            abort = true;
                                            POSFormsManager.ShowPOSMessageDialog(3593);
                                        }
                                        else
                                        {
                                            int textId = 0;
                                            if (inputConfirmation.EnteredText.Length == 0 && infoCode.InputRequired)
                                            {
                                                textId     = 3590; //The input text is required
                                                inputValid = false;
                                            }

                                            if (inputValid && infoCode.MinimumLength > 0 && inputConfirmation.EnteredText.Length < infoCode.MinimumLength)
                                            {
                                                textId     = 3591; //The input text is too short.
                                                inputValid = false;
                                            }

                                            if (inputValid && infoCode.MaximumLength > 0 && inputConfirmation.EnteredText.Length > infoCode.MaximumLength)
                                            {
                                                textId     = 3592; //The input text exceeds the maximum length.
                                                inputValid = false;
                                            }

                                            if (inputValid && infoCode.AdditionalCheck == 1)
                                            {
                                                inputValid = CheckKennitala(inputConfirmation.EnteredText);
                                                if (!inputValid)
                                                {
                                                    textId = 3603;
                                                }
                                            }

                                            if (!inputValid)
                                            {
                                                POSFormsManager.ShowPOSMessageDialog(textId);
                                            }
                                        }
                                        infoCode.Information = inputConfirmation.EnteredText;
                                    }
                                    else
                                    {
                                        inputValid = infoCode.InputRequired;
                                    }
                                }
                                                                                                          );


                                Application.Services.Interaction.InteractionRequest(request);

                                if (abort)
                                {
                                    return(false);
                                }
                            } while (!inputValid);
                            //Adding the result to the infocode
                        }

                        #endregion

                        #region Date
                        else if (infoCode.InputType == InfoCodeInputType.Date)
                        {
                            Boolean inputValid = true;
                            do
                            {
                                inputValid = true;

                                string inputText;
                                //Show the input form
                                using (frmInputNumpad inputDialog = new frmInputNumpad())
                                {
                                    inputDialog.EntryTypes = NumpadEntryTypes.Date;
                                    inputDialog.PromptText = infoCode.Prompt;
                                    POSFormsManager.ShowPOSForm(inputDialog);
                                    // Quit if cancel is pressed...
                                    if (inputDialog.DialogResult == System.Windows.Forms.DialogResult.Cancel && !infoCode.InputRequired)
                                    {
                                        return(false);
                                    }

                                    inputText = inputDialog.InputText;
                                }

                                //Is input valid?
                                if (!string.IsNullOrEmpty(inputText))
                                {
                                    int      textId   = 0;
                                    bool     isDate   = true;
                                    DateTime infoDate = DateTime.Now;

                                    try
                                    {
                                        infoDate = Convert.ToDateTime(inputText, (IFormatProvider)Thread.CurrentThread.CurrentCulture.DateTimeFormat);
                                    }
                                    catch
                                    {
                                        isDate = false;
                                    }

                                    if (!isDate)
                                    {
                                        textId     = 3602; //Date entered is not valid
                                        inputValid = false;
                                    }

                                    if (inputText.Length == 0 && infoCode.InputRequired)
                                    {
                                        textId     = 3594; //A number input is required
                                        inputValid = false;
                                    }

                                    if (!inputValid)
                                    {
                                        POSFormsManager.ShowPOSMessageDialog(textId);
                                    }
                                    else
                                    {
                                        //Setting the result to the infocode
                                        infoCode.Information = infoDate.ToString(Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern);
                                    }
                                }
                                else if (infoCode.InputRequired)
                                {
                                    inputValid = false;
                                    POSFormsManager.ShowPOSMessageDialog(3597);//A number input is required
                                }
                            } while (!inputValid);
                        }

                        #endregion

                        #region Numeric and Operator/Staff

                        else if (infoCode.InputType == InfoCodeInputType.Numeric || infoCode.InputType == InfoCodeInputType.Operator)
                        {
                            Boolean inputValid = true;

                            do
                            {
                                inputValid = true;

                                string inputText = string.Empty;
                                //Show the input form
                                using (frmInputNumpad inputDialog = new frmInputNumpad())
                                {
                                    inputDialog.EntryTypes = NumpadEntryTypes.Price;
                                    inputDialog.PromptText = infoCode.Prompt;
                                    POSFormsManager.ShowPOSForm(inputDialog);
                                    // Quit if cancel is pressed and input not required...
                                    if (inputDialog.DialogResult == System.Windows.Forms.DialogResult.Cancel && !infoCode.InputRequired)
                                    {
                                        return(false);
                                    }

                                    // If input required then only valid result is Ok.
                                    if (inputDialog.DialogResult == System.Windows.Forms.DialogResult.OK)
                                    {
                                        inputText = inputDialog.InputText;
                                    }
                                }

                                //Is input empty?
                                if (!string.IsNullOrWhiteSpace(inputText))
                                {
                                    int textId = 0;
                                    if (inputText.Length == 0 && infoCode.InputRequired)
                                    {
                                        textId     = 3594; //A number input is required
                                        inputValid = false;
                                    }

                                    if (infoCode.MinimumValue != 0 && Convert.ToDecimal(inputText) < infoCode.MinimumValue)
                                    {
                                        textId     = 3595; //The number is lower than the minimum value
                                        inputValid = false;
                                    }

                                    if (infoCode.MaximumValue != 0 && Convert.ToDecimal(inputText) > infoCode.MaximumValue)
                                    {
                                        textId     = 3596; //The number exceeds the maximum value
                                        inputValid = false;
                                    }

                                    if (!inputValid)
                                    {
                                        POSFormsManager.ShowPOSMessageDialog(textId);
                                    }
                                }
                                else
                                {
                                    inputValid = false;
                                    POSFormsManager.ShowPOSMessageDialog(3597); //A number input is required
                                }

                                //Setting the result to the infocode
                                infoCode.Information = inputText;
                            } while (!inputValid);
                        }

                        #endregion

                        #region Customer

                        else if (infoCode.InputType == InfoCodeInputType.Customer)
                        {
                            bool inputValid = true;
                            do
                            {
                                inputValid = true;
                                Contracts.DataEntity.ICustomer customer = this.Application.Services.Customer.Search();
                                if (customer != null)
                                {
                                    infoCode.Information = customer.CustomerId;
                                    inputValid           = true;
                                }
                                else
                                {
                                    if (infoCode.InputRequired)
                                    {
                                        inputValid = false;
                                        POSFormsManager.ShowPOSMessageDialog(3598); //A customer needs to be selected
                                    }
                                }
                            } while (!inputValid);
                        }
                        #endregion

                        #region Item

                        else if (infoCode.InputType == InfoCodeInputType.Item)
                        {
                            Boolean inputValid = true;
                            do
                            {
                                string       selectedItemID = string.Empty;
                                DialogResult dialogResult   = this.Application.Services.Dialog.ItemSearch(500, ref selectedItemID);
                                // Quit if cancel is pressed...
                                if (dialogResult == System.Windows.Forms.DialogResult.Cancel && !infoCode.InputRequired)
                                {
                                    return(false);
                                }

                                if (!string.IsNullOrEmpty(selectedItemID))
                                {
                                    infoCode.Information = selectedItemID;
                                    inputValid           = true;
                                }
                                else
                                {
                                    if (infoCode.InputRequired)
                                    {
                                        inputValid = false;
                                        POSFormsManager.ShowPOSMessageDialog(3599);//A items needs to be selected
                                    }
                                }
                            } while (!inputValid);
                        }
                        #endregion

                        #region SubCode

                        else if ((infoCode.InputType == InfoCodeInputType.SubCodeList) || (infoCode.InputType == InfoCodeInputType.SubCodeButtons))
                        {
                            FormInfoCodeSubCodeBase infoSubCodeDialog;
                            if (infoCode.InputType == InfoCodeInputType.SubCodeList)
                            {
                                infoSubCodeDialog = new FormInfoCodeSubCodeList();
                            }
                            else
                            {
                                infoSubCodeDialog = new FormInfoSubCode();
                            }

                            using (infoSubCodeDialog)
                            {
                                bool inputValid = false;
                                do
                                {
                                    infoSubCodeDialog.InfoCodePrompt = infoCode.Prompt;
                                    infoSubCodeDialog.InfoCodeId     = infoCode.InfocodeId;
                                    infoSubCodeDialog.InputRequired  = infoCode.InputRequired;

                                    POSFormsManager.ShowPOSForm(infoSubCodeDialog);
                                    switch (infoSubCodeDialog.DialogResult)
                                    {
                                    case DialogResult.OK:
                                        inputValid = true;
                                        break;

                                    case DialogResult.No:
                                        return(false);

                                    default:
                                        if (!infoCode.InputRequired)
                                        {
                                            return(false);
                                        }
                                        break;
                                    }

                                    //if InputValid is false then nothing was selected in the dialog and there is no point in going through this code
                                    if (inputValid)
                                    {
                                        infoCode.Information = infoSubCodeDialog.SelectedDescription;
                                        infoCode.Subcode     = infoSubCodeDialog.SelectedSubcodeId;

                                        //TenderDeclarationTransaction also has infocodes but it can't have any sale items so no need
                                        //to go through this code.
                                        if (retailTransaction != null)
                                        {
                                            //Look through the information on the subcode that was selected and see if an item is to be sold
                                            //and if a discount and/or price needs to be modified
                                            //foreach (SubcodeInfo subcodeInfo in infoSubCodeDialog.SubCodes)
                                            //{
                                            if ((infoSubCodeDialog.SelectedTriggerFunction == (int)TriggerFunctionEnum.Item) && (infoSubCodeDialog.SelectedTriggerCode.Length != 0))
                                            {
                                                OperationInfo opInfo = new OperationInfo();

                                                ItemSale itemSale = new ItemSale();
                                                itemSale.OperationID    = PosisOperations.ItemSale;
                                                itemSale.OperationInfo  = opInfo;
                                                itemSale.Barcode        = infoSubCodeDialog.SelectedTriggerCode;
                                                itemSale.POSTransaction = retailTransaction;
                                                itemSale.RunOperation();

                                                //The infocode item has been added.
                                                //Look at the last item on the transaction and if it is the same item that the ItemSale was supposed to sell
                                                //then check to see if it is to have a special price or discount
                                                if (retailTransaction.SaleItems.Last.Value.ItemId == infoSubCodeDialog.SelectedTriggerCode)
                                                {
                                                    //set the property of that item to being an infocode item such that if the same item is added again, then
                                                    //these will not be aggregated (since the item as infocode item might receive a different discount than the same
                                                    //item added regularly.
                                                    retailTransaction.SaleItems.Last.Value.IsInfoCodeItem = true;

                                                    infoCode.SubcodeSaleLineId = retailTransaction.SaleItems.Last.Value.LineId;

                                                    if (infoSubCodeDialog.SelectedPriceType == (int)PriceTypeEnum.Price)
                                                    {
                                                        PriceOverride priceOverride = new PriceOverride();

                                                        opInfo.NumpadValue = infoSubCodeDialog.SelectedAmountPercent.ToString("n2");
                                                        opInfo.ItemLineId  = retailTransaction.SaleItems.Last.Value.LineId;

                                                        priceOverride.OperationInfo  = opInfo;
                                                        priceOverride.OperationID    = PosisOperations.PriceOverride;
                                                        priceOverride.POSTransaction = retailTransaction;
                                                        priceOverride.LineId         = retailTransaction.SaleItems.Last.Value.LineId;
                                                        priceOverride.RunOperation();
                                                    }
                                                    else if (infoSubCodeDialog.SelectedPriceType == (int)PriceTypeEnum.Percent)
                                                    {
                                                        LineDiscountPercent lineDiscount = new LineDiscountPercent();

                                                        opInfo.NumpadValue = infoSubCodeDialog.SelectedAmountPercent.ToString("n2");
                                                        opInfo.ItemLineId  = retailTransaction.SaleItems.Last.Value.LineId;

                                                        lineDiscount.OperationInfo  = opInfo;
                                                        lineDiscount.OperationID    = PosisOperations.LineDiscountPercent;
                                                        lineDiscount.POSTransaction = retailTransaction;
                                                        lineDiscount.RunOperation();
                                                    }
                                                }
                                            }
                                        }
                                    }
                                } while (!inputValid);
                            }
                        }
                        #endregion

                        #region Age limit

                        else if ((infoCode.InputType == InfoCodeInputType.AgeLimit))
                        {
                            int ageLimit = (int)infoCode.MinimumValue;
                            if (ageLimit >= 0)
                            {
                                //Calculate birthdate corresponding to minimum age limit
                                DateTime dtBirthDate = DateTime.Today.AddYears(-ageLimit);

                                //Convert the date time value according to the current culture information
                                string birthDate = dtBirthDate.ToString(System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern);
                                string msg       = ApplicationLocalizer.Language.Translate(3606, ageLimit, birthDate);

                                // Process age limit info codes if it is pre item and prompt the message to user for processing.
                                // Also Info Code type is an item and Age Limit is a link to reason code then process the info code with prompt to user.
                                if (((tableRefId == InfoCodeTableRefType.PreItem) && (infoCode.InputType == InfoCodeInputType.AgeLimit)) || (!string.IsNullOrEmpty(linkedInfoCodeId) && tableRefId == InfoCodeTableRefType.Item))
                                {
                                    using (frmMessage frmMsg = new frmMessage(msg, MessageBoxButtons.YesNo, MessageBoxIcon.Information, false))
                                    {
                                        POSFormsManager.ShowPOSForm(frmMsg);
                                        if (frmMsg.DialogResult != DialogResult.Yes)
                                        {
                                            return(false);
                                        }
                                    }
                                }
                                infoCode.Information = msg;
                            }
                        }
                        #endregion

                        else
                        {
                            POSFormsManager.ShowPOSMessageDialog(3589);
                            return(false);
                        }

                        // Add the infocode to the transaction
                        if (infoCode.Information != null && infoCode.Information.Length > 0)
                        {
                            string infoComment = string.Empty;
                            if (infoCode.PrintPromptOnReceipt || infoCode.PrintInputOnReceipt || infoCode.PrintInputNameOnReceipt)
                            {
                                if (infoCode.PrintPromptOnReceipt && (infoCode.Prompt.Length != 0))
                                {
                                    infoComment = infoCode.Prompt;
                                }

                                if (infoCode.PrintInputOnReceipt && (infoCode.Subcode != null) && (infoCode.Subcode.Length != 0))
                                {
                                    if (infoComment.Length != 0)
                                    {
                                        infoComment += " - " + infoCode.Subcode;
                                    }
                                    else
                                    {
                                        infoComment = infoCode.Subcode;
                                    }
                                }

                                if (infoCode.PrintInputNameOnReceipt && (infoCode.Information.Length != 0))
                                {
                                    if (infoComment.Length != 0)
                                    {
                                        infoComment += " - " + infoCode.Information;
                                    }
                                    else
                                    {
                                        infoComment = infoCode.Information;
                                    }
                                }
                            }

                            if (infoCodeType == InfoCodeType.Sales)
                            {
                                int lineId;
                                if (infoCode.SubcodeSaleLineId != -1)
                                {
                                    SaleLineItem saleLineItem = retailTransaction.GetItem(infoCode.SubcodeSaleLineId - 1);
                                    saleLineItem.Add(infoCode);
                                    lineId = saleLineItem.LineId;
                                }
                                else
                                {
                                    // don't save if this is pre-item. the same infocodes will be found next pass for normal item infocodes.
                                    if (tableRefId == InfoCodeTableRefType.PreItem)
                                    {
                                        continue;
                                    }
                                    else
                                    {
                                        LinkedListNode <SaleLineItem> saleLineItem = retailTransaction.SaleItems.Last;
                                        saleLineItem.Value.Add(infoCode);
                                        lineId = saleLineItem.Value.LineId;
                                    }
                                }

                                if (infoComment.Trim().Length != 0)
                                {
                                    OperationInfo opInfo = new OperationInfo();
                                    opInfo.NumpadValue = infoComment.Trim();
                                    opInfo.ItemLineId  = lineId;

                                    ItemComment itemComment = new ItemComment();
                                    itemComment.OperationID    = PosisOperations.ItemComment;
                                    itemComment.POSTransaction = (PosTransaction)posTransaction;
                                    itemComment.OperationInfo  = opInfo;
                                    itemComment.RunOperation();
                                }
                            }
                            else if (infoCodeType == InfoCodeType.Payment)
                            {
                                if (retailTransaction != null)
                                {
                                    LinkedListNode <TenderLineItem> tenderLineItem = retailTransaction.TenderLines.Last;
                                    tenderLineItem.Value.Add(infoCode);

                                    if (infoComment.Trim().Length != 0)
                                    {
                                        tenderLineItem.Value.Comment = infoComment.Trim();
                                    }
                                }
                                else
                                {
                                    LSRetailPosis.Transaction.CustomerPaymentTransaction custPayTrans = posTransaction as LSRetailPosis.Transaction.CustomerPaymentTransaction;
                                    LinkedListNode <TenderLineItem> tenderLineItem = custPayTrans.TenderLines.Last;
                                    tenderLineItem.Value.Add(infoCode);

                                    if (infoComment.Trim().Length != 0)
                                    {
                                        tenderLineItem.Value.Comment = infoComment.Trim();
                                    }
                                }

                                //LinkedListNode<TenderLineItem> tenderLineItem = retailTransaction.TenderLines.Last; //
                                //tenderLineItem.Value.Add(infoCode);

                                //if (infoComment.Trim().Length != 0)
                                //{
                                //    tenderLineItem.Value.Comment = infoComment.Trim();
                                //}
                            }
                            else
                            {
                                if (retailTransaction != null)
                                {
                                    retailTransaction.Add(infoCode);
                                    if (infoComment.Trim().Length != 0)
                                    {
                                        retailTransaction.InvoiceComment += infoComment.Trim();
                                    }
                                }
                                else
                                {
                                    tenderCountTransaction.Add(infoCode);
                                    //No invoice comment on TenderDeclarationTransaction
                                }
                            }
                        }
                    }
                }
            }

            return(true);
        }