Ejemplo n.º 1
0
        public void RetrieveResponses(FormCollection collection)
        {
            List <QuestVal>   questvals  = new List <QuestVal>();
            List <ItemCounts> icounts    = new List <ItemCounts>();
            List <string>     shownItems = new List <string>();
            List <string>     setKeyIDs  = new List <string>();
            List <string>     QuestionsShown;

            //Request.Form
            try
            {
                QuestionsShown = Regex.Split(Request.Form["SectionLayout"].ToString(), ",").ToList();
            }
            catch
            {
                return;
            }
            string setKey = "";

            foreach (string key in Request.Form.Keys)
            {
                if (key.StartsWith("SPQuestion_") && !key.Contains("_ddl") && !key.Contains("_mddl"))
                {
                    QuestVal QV     = new QuestVal();
                    var      value  = collection[key];
                    string   Qindex = Regex.Split(key, "_")[1];
                    QV.QuestionID = Qindex;
                    QV.Response   = (string)value;

                    if (Request.Form.AllKeys.Contains(key + "_ddl"))
                    {
                        QV.DisplayResponse = collection[key + "_ddl"];
                    }

                    if (Request.Form.AllKeys.Contains(key + "_mddl"))
                    {
                        QV.Response        = QV.Response.Replace(",", "~");
                        QV.DisplayResponse = collection[key + "_mddl"];
                    }

                    questvals.Add(QV);

                    int listloc = 0;

                    foreach (string qid in QuestionsShown)
                    {
                        if (qid == QV.QuestionID)
                        {
                            QuestionsShown.RemoveAt(listloc);
                            break;
                        }
                        listloc++;
                    }
                }

                if (key.StartsWith("SPsetKey_"))
                {
                    string val = collection[key];
                    string cid = key.Remove(0, 9);
                    setKeyIDs.Add(cid);
                }

                if (key.StartsWith("SPShownItemCollection_"))
                {
                    string collectItems = collection[key];

                    shownItems.AddRange(Regex.Split(collectItems, "~~").ToList());
                }

                if (key.StartsWith("SPselectItemValues"))
                {
                    string thevalues    = collection[key];
                    string itemSelector = Regex.Split(key, "_")[2];
                    string ind          = Regex.Split(key, "_")[1];
                    if (thevalues != "~NoActivity~")
                    {
                        if (thevalues.StartsWith("~~"))
                        {
                            thevalues = thevalues.Remove(0, 2);
                        }
                        List <string> selectedVals = Regex.Split(thevalues, "~~").ToList();
                        foreach (string item in selectedVals)
                        {
                            ItemCounts IC = new ItemCounts();
                            IC.itemCode     = item;
                            IC.itemQuantity = 1;
                            IC.ownerOIS     = itemSelector;
                            icounts.Add(IC);
                        }
                        string collectItemsx = collection["SPSelectItemCollection_" + ind + "_" + itemSelector];

                        shownItems.AddRange(Regex.Split(collectItemsx, "~~").ToList());
                    }
                }
                if (key.StartsWith("SPitemcheck_"))
                {
                    string     itemSelector = Regex.Split(key, "_")[2];
                    string     itemCode     = key.Remove(0, 12 + itemSelector.Length + 3);
                    string     retval       = collection[key];
                    Int32      quant        = (retval == "on") ? 1 : 0;
                    ItemCounts IC           = new ItemCounts();
                    IC.itemCode     = itemCode;
                    IC.itemQuantity = quant;
                    IC.ownerOIS     = itemSelector;
                    icounts.Add(IC);
                }
                if (key.StartsWith("SPitemquant_"))
                {
                    string     itemSelector = Regex.Split(key, "_")[2];
                    string     itemCode     = key.Remove(0, 12 + itemSelector.Length + 3);
                    Int32      quant        = Convert.ToInt32(collection[key]);
                    ItemCounts IC           = new ItemCounts();
                    IC.itemCode     = itemCode;
                    IC.itemQuantity = quant;
                    IC.ownerOIS     = itemSelector;
                    icounts.Add(IC);
                }

                if (key == "SP_Notes")
                {
                    collection[key] = collection[key].Replace("\r", "");
                    collection[key] = collection[key].Replace("\n", "");
                    SessionManager.StoreContactNotes(HttpContext.Session, collection[key]);
                }
            }

            foreach (string qid in QuestionsShown)
            {
                QuestVal QV = new QuestVal();
                QV.QuestionID = qid;
                QV.Response   = "";
                questvals.Add(QV);
            }

            foreach (string item in shownItems)
            {
                bool foundit = false;
                foreach (ItemCounts iC in icounts)
                {
                    if (item == iC.itemCode)
                    {
                        foundit = true;
                        break;
                    }
                }
                if (!foundit)
                {
                    ItemCounts IC = new ItemCounts();
                    IC.itemCode     = item;
                    IC.itemQuantity = 0;
                    icounts.Add(IC);
                }
            }

            List <ItemOrdered> iOrd = new List <ItemOrdered>();

            foreach (ItemCounts iC in icounts)
            {
                ItemOrdered io = new ItemOrdered();
                io.ItemCode     = iC.itemCode;
                io.ItemQuantity = iC.itemQuantity;
                io.setKey       = (setKeyIDs.Exists(item => item == iC.ownerOIS)) ? true : false;
                io.oiOwner      = Convert.ToInt32(iC.ownerOIS);
                iOrd.Add(io);
            }


            SessionManager.AddUpdateOrderedItems(iOrd, HttpContext.Session);

            if (questvals.Count > 0)
            {
                SessionManager.AddUpdateQuestions(questvals, HttpContext.Session);
            }
        }