Exemple #1
0
        /// <summary>
        /// G마켓 상품 필수선택 정보 및 상세리스트 UI에 적합하게 조회
        /// </summary>
        public List<TempGepItemData> GetSourceItemOptionList(string gd_no, int stock_qty)
        {
            List<TempGepItemData> selections = new List<TempGepItemData>();

            SourceItemOptionInfoT info = new GmarketItemBiz().GetSourceItemOptionInfo(gd_no);
            if (info == null || info.SelectionInfoList == null || info.SelectionInfoList.Count == 0) return selections;

            if (info.DisplayType == "S")
            {
                List<SourceItemOptionRecordT> orgList = info.SelectionInfoList; // 순수하게 DB에서 가져온 원본리스트

                string[] nameArray = orgList.Select(t => t.Name).Distinct().ToArray(); // Name 추출
                List<List<SourceItemOptionRecordT>> selByName = new List<List<SourceItemOptionRecordT>>();
                int i = 0;

                // 각 Name에 대한 하위 값들을 추출
                foreach (string n in nameArray)
                {
                    var tmp = orgList.Where(t => t.Name == n).Select(t => new { OptionNo = t.OptionNo, Value = t.Value, Price = t.Price, Cnt = t.Cnt, Stat = t.Stat }).ToList();
                    List<SourceItemOptionRecordT> tmpList = new List<SourceItemOptionRecordT>();

                    foreach (var record in tmp)
                    {
                        SourceItemOptionRecordT s = new SourceItemOptionRecordT();
                        s.OptionNo = record.OptionNo;
                        s.Value = record.Value;
                        s.Price = record.Price;
                        s.Cnt = record.Cnt;
                        s.Stat = record.Stat == null ? "Y" : record.Stat;
                        tmpList.Add(s);
                    }

                    selByName.Add(tmpList);
                    i++;
                }

                // 조합형 데이터 생성
                for (int n = 0; n < selByName[0].Count; n++) // 첫번째 항목에 대한 리스트
                {
                    TempGepItemData sel = new TempGepItemData();
                    sel.sel_name = selByName[0][n].Value;
                    sel.sel_qty = info.IsSelectionInventory == false ? (Util.GetSafeString(selByName[0][n].Stat) == "N" ? 0 : stock_qty) : Util.GetSafeInt(selByName[0][n].Cnt);
                    sel.sel_price = Util.GetSafeInt(selByName[0][n].Price);
                    sel.sel_no = new BsonArray();
                    sel.sel_no.Add(selByName[0][n].OptionNo);

                    selections.Add(sel);
                }

                int mngCnt = 1;

                while (selByName.Count > mngCnt) // N번째 항목이 있다면
                {
                    List<TempGepItemData> tmpList = new List<TempGepItemData>();

                    for (int n = 0; n < selByName[mngCnt].Count; n++) // N번째 항목에 대한 리스트
                    {
                        TempGepItemData sel = new TempGepItemData();
                        sel.sel_name = selByName[mngCnt][n].Value;
                        sel.sel_qty = info.IsSelectionInventory == false ? (Util.GetSafeString(selByName[mngCnt][n].Stat) == "N" ? 0 : stock_qty) : Util.GetSafeInt(selByName[mngCnt][n].Cnt);
                        sel.sel_price = Util.GetSafeInt(selByName[mngCnt][n].Price);
                        sel.sel_no = new BsonArray();
                        sel.sel_no.Add(selByName[mngCnt][n].OptionNo);

                        for (int m = 0; m < selections.Count; m++)
                        {
                            TempGepItemData com = new TempGepItemData();
                            com.sel_name = selections[m].sel_name + " : " + sel.sel_name;
                            com.sel_qty = sel.sel_qty < selections[m].sel_qty ? sel.sel_qty : selections[m].sel_qty;
                            com.sel_price = selections[m].sel_price + sel.sel_price;
                            com.sel_no = new BsonArray();
                            com.sel_no.Add(selections[m].sel_no[0]);
                            if (mngCnt == 1) com.sel_no.Add(sel.sel_no[0]);
                            else if (mngCnt > 1) com.sel_no.Add(selections[m].sel_no[1]);
                            if (mngCnt == 2) com.sel_no.Add(sel.sel_no[0]);
                            else if (mngCnt > 2) com.sel_no.Add(selections[m].sel_no[2]);
                            if (mngCnt == 3) com.sel_no.Add(sel.sel_no[0]);
                            else if (mngCnt > 3) com.sel_no.Add(selections[m].sel_no[3]);
                            if (mngCnt == 4) com.sel_no.Add(sel.sel_no[0]);
                            else if (mngCnt > 4) com.sel_no.Add(selections[m].sel_no[4]);

                            tmpList.Add(com);
                        }
                    }

                    selections = tmpList;

                    mngCnt++;
                }
            }
            else
            {
                foreach (SourceItemOptionRecordT row in info.SelectionInfoList)
                {
                    TempGepItemData sel = new TempGepItemData();
                    sel.sel_name = row.Name + " : " + row.Value;
                    sel.sel_qty = info.IsSelectionInventory == false ? ((row.Stat != null && row.Stat == "N") ? 0 : stock_qty) : row.Cnt;
                    sel.sel_price = Util.GetSafeInt(row.Price);
                    sel.sel_no = new BsonArray();
                    sel.sel_no.Add(row.OptionNo);

                    selections.Add(sel);
                }
            }

            return selections;
        }
        /// <summary>
        /// G마켓 필수선택 기존 선택값 조회 리스트 데이터
        /// </summary>
        public List<TempGepItemData> GetGmarketOptionSelectList(string itemNo)
        {
            List<GepItemsData> list = new GmarketItemBiz().GetTempGEPItemList(MemberContext.LoginID, itemNo);

            List<TempGepItemData> reList = new List<TempGepItemData>();

            foreach (GepItemsData item in list)
            {
                TempGepItemData opt = new TempGepItemData();
                opt._id = item._id;
                opt.sel_name = item.src_info.sel_name;
                reList.Add(opt);
            }

            return reList;
        }