/// <summary> /// Fill the all the channel fields values from BF Itemdetail. /// Generate the necessary list items and call the functions to add the channel value. /// </summary> /// <param name="objChannel"></param> /// <param name="item_guid"></param> /// <param name="oItem"></param> private void GenerateChannelFeed(ref ChannelSale objChannel, Guid item_guid, ItemDetail oItem) { #region "Variables" dsItemDetail.ItemsRow itemRow = null; dsItemDetail.ItemSitesRow itemSitesRow = null; dsItemDetail.ItemVendorsRow itemVendorsRow = null; dsItemDetail.ItemCatalogsRow itemCatalogsRow = null; List<dsItemDetail.ItemImagesRow> lstItemImagesRow = null; List<dsItemDetail.ItemAssociationsRow> lstItemAssociationsRow = null; List<dsItemDetail.ItemCategoriesRow> lstItemCategoriesRow = null; #endregion try { if (null != objChannel && null != item_guid && null != oItem && 0 < oItem.Items.Count) { itemRow = oItem.Items.AsEnumerable().AsQueryable().OfType<dsItemDetail.ItemsRow>().Where(O => O.item_guid == item_guid).FirstOrDefault(); itemSitesRow = oItem.ItemSites.AsEnumerable().AsQueryable().OfType<dsItemDetail.ItemSitesRow>().Where(O => O.site_guid == new Guid(strBabyHavenSiteGuid) && O.item_guid == item_guid).FirstOrDefault(); itemVendorsRow = oItem.ItemVendors.AsEnumerable().AsQueryable().OfType<dsItemDetail.ItemVendorsRow>().Where(O => O.item_guid == item_guid).FirstOrDefault(); itemCatalogsRow = oItem.ItemCatalogs.AsEnumerable().AsQueryable().OfType<dsItemDetail.ItemCatalogsRow>().Where(O => O.item_guid == item_guid && O.catalog_guid == new Guid(strBabyHavenCatalogGuid)).FirstOrDefault(); lstItemImagesRow = oItem.ItemImages.AsEnumerable().AsQueryable().OfType<dsItemDetail.ItemImagesRow>().Where(O => O.item_guid == item_guid).ToList(); lstItemAssociationsRow = oItem.ItemAssociations.AsEnumerable().AsQueryable().OfType<dsItemDetail.ItemAssociationsRow>().Where(O => O.parent_guid == item_guid).ToList(); lstItemCategoriesRow = oItem.ItemCategories.AsEnumerable().AsQueryable().OfType<dsItemDetail.ItemCategoriesRow>().Where(O => O.item_guid == item_guid).ToList(); if (null != itemRow) { AddItemdetailToChannel(ref objChannel, itemRow, false); AddItemSitesToChannel(ref objChannel, itemSitesRow); AddItemVendorToChannel(ref objChannel, itemVendorsRow); AddItemCatalogToChannel(ref objChannel, itemCatalogsRow); AddItemImageToChannel(ref objChannel, lstItemImagesRow); objChannel.MerchantCategory = GetCategoryTree(lstItemCategoriesRow); CheckKititemWithSingleAssociation(ref objChannel, itemRow, lstItemAssociationsRow); } } } catch (Exception ex) { Console.WriteLine("EXCEPTION. While GenerateChannelFeed: " + ex.Message); log.Error("GenerateChannelFeed: ", ex); } }
/// <summary> /// If channel item dont have the value and if it has only one associated master item then fill the master item value to channel. /// </summary> /// <param name="objChannel"></param> /// <param name="itemRow"></param> /// <param name="lstItemAssociationsRow"></param> private void CheckKititemWithSingleAssociation(ref ChannelSale objChannel, dsItemDetail.ItemsRow itemRow, List<dsItemDetail.ItemAssociationsRow> lstItemAssociationsRow) { try { if (!itemRow.Isitem_type_idNull()) { objChannel.Master = (itemRow.item_type_id == 3 ? "1" : string.Empty); if (!itemRow.Isitem_sub_type_idNull() && 1 == itemRow.item_sub_type_id && 1 == itemRow.item_type_id) { objChannel.ChildItem = "1"; if (string.IsNullOrEmpty(Convert.ToString(objChannel.FreeShipping.Trim())) && !itemRow.Isitem_wholesale_priceNull()) objChannel.FreeShipping = (itemRow.item_wholesale_price >= 100M ? "Yes" : "No"); } if (1 == itemRow.item_type_id && !itemRow.Ismaster_guidNull() && !itemRow.Ismaster_item_cdNull()) objChannel.AssociatedMaster = itemRow.master_item_cd; } //Kit item if (!itemRow.Isitem_type_idNull() && !itemRow.Isitem_sub_type_idNull() && 1 == itemRow.item_type_id && 2 == itemRow.item_sub_type_id && null != lstItemAssociationsRow && 1 == lstItemAssociationsRow.Count && !lstItemAssociationsRow[0].Isitem_guidNull()) { objChannel.IsNeedKitItemData = true; objChannel.AssociatedMasterItemGuid = lstItemAssociationsRow[0].item_guid; } } catch (Exception ex) { Console.WriteLine("EXCEPTION. While CheckKititemWithSingleAssociation: " + ex.Message); log.Error("CheckKititemWithSingleAssociation: ", ex); } }
/// <summary> /// Get all the available items from BF and loop the ItemGetdetail Fill all the values into Datatable. /// (Night process) /// </summary> public void ChannelDownloadFull() { #region "Variables" List<ChannelSale> lstChannel = null; ChannelSale objChannel = null; List<Guid> lstItemGuids = null; List<Guid> lstBatchItemGuids = null; ItemDetail itemDetail = null; int batchProcessPageNumber = 0; int iCount = 0; #endregion try { lstChannel = new List<ChannelSale>() { }; lstItemGuids = GetAllItemGuids(); if (null != lstItemGuids && 0 < lstItemGuids.Count) { Console.WriteLine("Total items count: " + lstItemGuids.Count); do { lstBatchItemGuids = lstItemGuids.Skip(batchProcessPageNumber * RECORDS_PER_PROCESS_BATCH).Take(RECORDS_PER_PROCESS_BATCH).ToList(); batchProcessPageNumber++; if (null != lstBatchItemGuids && 0 < lstBatchItemGuids.Count) { Console.WriteLine(string.Format("*** Processing item batch {0} of {1}", batchProcessPageNumber, (Math.Round(0.00 + lstItemGuids.Count / RECORDS_PER_PROCESS_BATCH, 0)).ToString())); itemDetail = GetItemsDetail(lstBatchItemGuids, false); if (null != itemDetail && null != itemDetail.Items && 0 < itemDetail.Items.Count) { foreach (dsItemDetail.ItemsRow itemRow in itemDetail.Items) { iCount++; Console.WriteLine(iCount + ". Processing item code: " + (itemRow.Isitem_cdNull() ? "" : itemRow.item_cd)); var varSiteGuid = itemDetail.Items.AsEnumerable().AsQueryable().OfType<dsItemDetail.ItemsRow>().ToList().Join(itemDetail.ItemSites.AsEnumerable().AsQueryable().OfType<dsItemDetail.ItemSitesRow>().ToList(), A => A.item_guid, B => B.item_guid, (A, B) => new { A.item_guid, B.site_guid }).SingleOrDefault(P => P.item_guid == itemRow.item_guid && P.site_guid == new Guid(strBabyHavenSiteGuid)); if (null != varSiteGuid && 0 == varSiteGuid.site_guid.CompareTo(new Guid(strBabyHavenSiteGuid))) { objChannel = new ChannelSale(); GenerateChannelFeed(ref objChannel, itemRow.item_guid, itemDetail); lstChannel.Add(objChannel); } } } } } while (lstBatchItemGuids.Count > 0); if (null != lstChannel && 0 < lstChannel.Count) { //Add kit item details. If it has single association item FillKitItemDetails(ref lstChannel); //Add kit item(Child) details. If it has single association item FillKitItemAssociatedChildDetails(ref lstChannel); //Fill the attribute value intead of guid FillAttributeValueFromGuid(ref lstChannel); //Set the default value to channel. Set the Size of the fields. NormalizeChannel(ref lstChannel); //Export Channel feed file. ExportExcel(lstChannel); } } } catch (Exception ex) { log.Error("\n\n ChannelDownloadFull: ", ex); } }
/// <summary> /// Add the BF item vendor details to channel feed. /// </summary> /// <param name="objChannel"></param> /// <param name="itemVendorsRow"></param> private void AddItemVendorToChannel(ref ChannelSale objChannel, dsItemDetail.ItemVendorsRow itemVendorsRow) { try { if (null != itemVendorsRow && !itemVendorsRow.Isvendor_item_cdNull()) objChannel.ManufacturerModel = (itemVendorsRow.vendor_item_cd.Length > 40 ? itemVendorsRow.vendor_item_cd.Substring(0, 39) : itemVendorsRow.vendor_item_cd); } catch (Exception ex) { Console.WriteLine("EXCEPTION. While AddItemVendorToChannel: " + ex.Message); log.Error("AddItemVendorToChannel: ", ex); } }
/// <summary> /// Get the item available and stock quantity from item site. /// </summary> /// <param name="objChannel"></param> /// <param name="itemSitesRow"></param> private void AddItemSitesToChannel(ref ChannelSale objChannel, dsItemDetail.ItemSitesRow itemSitesRow) { try { if (null != itemSitesRow && !itemSitesRow.Issite_quantity_on_handNull() && !itemSitesRow.Issite_quantity_on_holdNull()) { objChannel.AvailableInventory = Convert.ToString(itemSitesRow.site_quantity_on_hand - itemSitesRow.site_quantity_on_hold); objChannel.StockQuantity = Convert.ToString(itemSitesRow.site_quantity_on_hand - itemSitesRow.site_quantity_on_hold); } } catch (Exception ex) { Console.WriteLine("EXCEPTION. While AddItemSitesToChannel: " + ex.Message); log.Error("AddItemSitesToChannel: ", ex); } }
/// <summary> /// Add the BF item image details to channel feed. /// </summary> /// <param name="objChannel"></param> /// <param name="lstItemImagesRow"></param> private void AddItemImageToChannel(ref ChannelSale objChannel, List<dsItemDetail.ItemImagesRow> lstItemImagesRow) { try { if (null != lstItemImagesRow && 0 < lstItemImagesRow.Count) { foreach (dsItemDetail.ItemImagesRow itemImagesRow in lstItemImagesRow) { if (!itemImagesRow.Isimage_guidNull() && !itemImagesRow.Isitem_image_type_idNull()) { string strImageUrl = string.Format("http://cas07.businessflow.ms/Current/Media/item_image_sheet.aspx?domain=strollerbabies.com&item_guid={0}&image_guid={1}.jpg", itemImagesRow.item_guid, itemImagesRow.image_guid); if (1 == itemImagesRow.item_image_type_id) objChannel.AdditionalImageURL1 = strImageUrl; else if (2 == itemImagesRow.item_image_type_id) objChannel.AdditionalImageURL2 = strImageUrl; else if (3 == itemImagesRow.item_image_type_id) objChannel.AdditionalImageURL3 = strImageUrl; } } } } catch (Exception ex) { Console.WriteLine("EXCEPTION. While AddItemImageToChannel: " + ex.Message); log.Error("AddItemImageToChannel: ", ex); } }
/// <summary> /// Add the BF item details to channel feed. /// </summary> /// <param name="objChannel"></param> /// <param name="itemRow"></param> private void AddItemdetailToChannel(ref ChannelSale objChannel, dsItemDetail.ItemsRow itemRow, bool isKitAssociatedItem = false) { PropertyDescriptorCollection pdCollectionChannel = null; try { pdCollectionChannel = TypeDescriptor.GetProperties(objChannel); foreach (PropertyDescriptor pdChannel in pdCollectionChannel) { PropertyInfo pInfo = null; if (!string.IsNullOrEmpty(pdChannel.Description) && itemRow.Table.Columns.Contains(pdChannel.Description) && itemRow[pdChannel.Description] != DBNull.Value) { //if (!isKitAssociatedItem || !strRemoveKitAssociatedItem.Split(',').Contains(pdChannel.Name)) if (!isKitAssociatedItem || strKitAssociatedItemAttributes.Split(',').Contains(pdChannel.Name)) { pInfo = objChannel.GetType().GetProperty(pdChannel.Name); if (null != pInfo && string.IsNullOrEmpty(Convert.ToString(pInfo.GetValue(objChannel, null)))) pdChannel.SetValue(objChannel, Convert.ToString(itemRow[pdChannel.Description])); } } } } catch (Exception ex) { Console.WriteLine("EXCEPTION. While AddItemdetailToChannel: " + ex.Message); log.Error("\n AddItemdetailToChannel: ", ex); } }
/// <summary> /// Add the BF item catalog details to channel feed. /// </summary> /// <param name="objChannel"></param> /// <param name="itemCatalogsRow"></param> private void AddItemCatalogToChannel(ref ChannelSale objChannel, dsItemDetail.ItemCatalogsRow itemCatalogsRow) { try { if (null != itemCatalogsRow) objChannel.ProductURL = string.Format("http://www.babyhaven.com/product_details.aspx?item_guid={0}", itemCatalogsRow.item_guid); } catch (Exception ex) { Console.WriteLine("EXCEPTION. While AddItemCatalogToChannel: " + ex.Message); log.Error("AddItemCatalogToChannel: ", ex); } }