public void Refresh(MarketplaceView view)
        {
            using (_dataContext = new berkeleyEntities())
            {
                if (view.Host.Equals("Ebay"))
                {
                    int marketplaceID = int.Parse(view.ID.Split(new Char[1] {
                        '-'
                    })[1]);

                    MarketplaceView newView = CreateMarketplaceView(_dataContext.EbayMarketplaces.Single(p => p.ID == marketplaceID));
                    view.ListingsLastSync = newView.ListingsLastSync;
                    view.OrdersLastSync   = newView.OrdersLastSync;
                    view.Name             = newView.Name;
                    view.Host             = newView.Host;
                }
                else if (view.Host.Equals("Amazon"))
                {
                    int marketplaceID = int.Parse(view.ID.Split(new Char[1] {
                        '-'
                    })[1]);

                    MarketplaceView newView = CreateMarketplaceView(_dataContext.AmznMarketplaces.Single(p => p.ID == marketplaceID));
                    view.ListingsLastSync = newView.ListingsLastSync;
                    view.OrdersLastSync   = newView.OrdersLastSync;
                    view.Name             = newView.Name;
                    view.Host             = newView.Host;
                }
            }
        }
Esempio n. 2
0
        private void ExportCountingData()
        {
            StringBuilder sb = new StringBuilder();

            using (berkeleyEntities dataContext = new berkeleyEntities())
            {
                var entries = dataContext.InventoryEntries.Where(p => p.PhysicalInventory.Code.Equals(_inventoryRef));

                foreach (InventoryEntry entry in entries)
                {
                    sb.AppendLine(string.Format("{0}\t{1}\t{2}", entry.Item.ItemLookupCode, entry.Counted, entry.LastModified));
                }
            }

            SaveFileDialog sfd = new SaveFileDialog();

            sfd.AddExtension = true;
            sfd.Filter       = "(*.txt)|*.txt|All Files (*.*)|*.*";
            sfd.DefaultExt   = ".txt";
            sfd.ShowDialog();

            if (!string.IsNullOrWhiteSpace(sfd.FileName))
            {
                File.WriteAllText(sfd.FileName, sb.ToString());
            }
        }
Esempio n. 3
0
        private void LoadLog()
        {
            tvHistory.Nodes.Clear();

            using (berkeleyEntities dataContext = new berkeleyEntities())
            {
                var entries = dataContext.Bsi_LocationLog.Where(p => p.User.Equals(_userName) && p.UpdateDate.Day == DateTime.Now.Day);

                var entryGroups = entries.GroupBy(p => p.Location);

                foreach (var entryGroup in entryGroups)
                {
                    TreeNode parentNode = new TreeNode();
                    parentNode.Name = entryGroup.Key;
                    parentNode.Text = entryGroup.Key;


                    foreach (Bsi_LocationLog entry in entryGroup)
                    {
                        TreeNode node = new TreeNode();
                        node.Name = entry.Item.ItemLookupCode + "  (" + entry.Quantity.ToString() + ")  (" + entry.BeforeChange + ")";
                        node.Text = entry.Item.ItemLookupCode + "  (" + entry.Quantity.ToString() + ")  (" + entry.BeforeChange + ")";

                        parentNode.Nodes.Add(node);
                    }

                    tvHistory.Nodes.Add(parentNode);
                }
            }
        }
Esempio n. 4
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            DateTime from = dtpFrom.Value.Date;
            DateTime to   = dtpTo.Value.Date;

            List <WorkDay> workDays = new List <WorkDay>();

            using (_dataContext = new berkeleyEntities())
            {
                for (DateTime currentDate = from; currentDate <= to; currentDate += TimeSpan.FromDays(1))
                {
                    WorkDay workDay = new WorkDay();

                    workDay.Date = currentDate;

                    GetReceivedCounts(workDay);

                    GetPictureCounts(workDay);

                    GetShippingCounts(workDay);

                    GetReturnCounts(workDay);

                    workDays.Add(workDay);
                }
            }

            dgvWorkByDay.DataSource = workDays;
        }
Esempio n. 5
0
 private void LoginForm_Load(object sender, EventArgs e)
 {
     using (berkeleyEntities dataContext = new berkeleyEntities())
     {
         cbPhysicalInventory.DataSource = dataContext.PhysicalInventories.Where(p => p.CloseTime == null).Select(p => p.Code);
     }
 }
Esempio n. 6
0
        private void Persist(ListingDto listingDto, string sellingState)
        {
            using (berkeleyEntities dataContext = new berkeleyEntities())
            {
                BonanzaListing listing = new BonanzaListing();

                listing.MarketplaceID   = _marketplace.ID;
                listing.Code            = listingDto.Code;
                listing.FullDescription = listingDto.FullDescription;
                listing.Title           = listingDto.Title;
                listing.Status          = sellingState;
                listing.LastSyncTime    = DateTime.UtcNow;
                listing.Sku             = listingDto.Sku;
                listing.IsVariation     = listingDto.IsVariation;

                foreach (ListingItemDto listingItemDto in listingDto.Items)
                {
                    BonanzaListingItem listingItem = new BonanzaListingItem();
                    listingItem.Listing  = listing;
                    listingItem.Item     = dataContext.Items.Single(p => p.ItemLookupCode.Equals(listingItemDto.Sku));
                    listingItem.Quantity = listingItemDto.Qty.Value;
                    listingItem.Price    = listingItemDto.Price.Value;
                }

                dataContext.SaveChanges();
            }
        }
Esempio n. 7
0
        private void btnAccept_Click(object sender, EventArgs e)
        {
            var locations = lbDeleteList.Items.Cast <string>();

            if (locations.Count() == 0)
            {
                MessageBox.Show("delete list is empty");
                return;
            }

            DialogResult dr = MessageBox.Show("Are you sure you want to clean all locations in delete list ?", "Confirm", MessageBoxButtons.OKCancel);

            if (dr.Equals(DialogResult.Cancel))
            {
                return;
            }

            int deleteCount = 0;

            using (berkeleyEntities dataContext = new berkeleyEntities())
            {
                foreach (string location in locations)
                {
                    var items = dataContext.Items.Where(p => p.BinLocation.Contains(location));

                    foreach (Item item in items)
                    {
                        List <string> currentBins = item.BinLocation.Split(new Char[1] {
                            ' '
                        }).ToList();

                        currentBins.ForEach(p => p = p.ToUpper().Trim());

                        if (currentBins.Any(p => p.Equals(location)))
                        {
                            Bsi_LocationLog logEntry = new Bsi_LocationLog();
                            logEntry.Item         = item;
                            logEntry.Location     = "- " + location;
                            logEntry.Quantity     = 0;
                            logEntry.User         = _user;
                            logEntry.UpdateDate   = DateTime.Now;
                            logEntry.BeforeChange = item.BinLocation;

                            deleteCount     += currentBins.RemoveAll(p => p.Equals(location));
                            item.BinLocation = String.Join(" ", currentBins).Trim();
                        }
                    }
                }
                dataContext.SaveChanges();
            }

            MessageBox.Show(deleteCount.ToString() + " locations deleted");


            this.Close();
        }
Esempio n. 8
0
        private void GetProductData(IEnumerable <Entry> entries)
        {
            using (berkeleyEntities dataContext = new berkeleyEntities())
            {
                _marketplace = dataContext.AmznMarketplaces.Single(p => p.ID == 1);

                foreach (Entry entry in entries)
                {
                    entry.UPC = dataContext.Items.Single(p => p.ItemLookupCode.Equals(entry.Sku)).GTIN;
                }
            }
        }
Esempio n. 9
0
        private static void SyncAmazonListings()
        {
            using (berkeleyEntities dataContext = new berkeleyEntities())
            {
                foreach (AmznMarketplace marketplace in dataContext.AmznMarketplaces)
                {
                    _amznServices.SynchronizeListings(marketplace.ID);

                    _logger.Info(marketplace.Name + " listings synchronization completed");
                }
            }
        }
        //public IEnumerable<MarketplaceView> GetAllExtendedMarketplaceViews()
        //{
        //    List<MarketplaceView> views = new List<MarketplaceView>();


        //    using (_dataContext = new berkeleyEntities())
        //    {
        //        foreach (EbayMarketplace marketplace in _dataContext.EbayMarketplaces)
        //        {
        //            views.Add(CreateExtendedMarketplaceView(marketplace));
        //        }


        //        foreach (AmznMarketplace marketplace in _dataContext.AmznMarketplaces)
        //        {
        //            views.Add(CreateExtendedMarketplaceView(marketplace));
        //        }
        //    }

        //    return views;
        //}

        public void GetAdditionalData(MarketplaceView view)
        {
            using (_dataContext = new berkeleyEntities())
            {
                if (view.Host.Equals("Amazon"))
                {
                    var activeListings = _dataContext.AmznListingItems.Where(p => p.MarketplaceID == view.DbID && p.IsActive);

                    view.ActiveListingQty = activeListings.Sum(p => p.Quantity);
                    view.ActiveListing    = activeListings.Count();

                    var orders = _dataContext.AmznOrders.Where(p => p.MarketplaceID == view.DbID);

                    var unshippedOrders = orders.Where(p => p.Status.Equals("Unshipped") || p.Status.Equals("PartiallyShipped"));
                    var unpaidOrders    = orders.Where(p => p.Status.Equals("Pending"));

                    if (unshippedOrders.Count() > 0)
                    {
                        view.WaitingShipmentQty = unshippedOrders.Sum(p => p.OrderItems.Sum(s => s.QuantityOrdered - s.QuantityShipped));
                        view.WaitingShipment    = unshippedOrders.Select(p => p.Code).ToList();
                    }


                    if (unpaidOrders.Count() > 0)
                    {
                        view.WaitingPaymentQty = unpaidOrders.Sum(p => p.OrderItems.Sum(s => s.QuantityOrdered - s.QuantityShipped));
                        view.WaitingPayment    = unpaidOrders.Select(p => p.Code).ToList();
                    }
                }
                else if (view.Host.Equals("Ebay"))
                {
                    var activeListings = _dataContext.EbayListings.Where(p => p.MarketplaceID == view.DbID && p.Status.Equals(EbayMarketplace.STATUS_ACTIVE));

                    view.ActiveListingQty = activeListings.Sum(p => p.ListingItems.Sum(s => s.Quantity));
                    view.ActiveListing    = activeListings.Count();


                    var orders = _dataContext.EbayOrders.Where(p => p.MarketplaceID == view.DbID).ToList();

                    var unshippedOrders = orders.Where(p => p.IsWaitingForShipment());
                    var unpaidOrders    = orders.Where(p => p.IsWaitingForPayment());



                    view.WaitingShipmentQty = unshippedOrders.Sum(p => p.OrderItems.Sum(s => s.QuantityPurchased));
                    view.WaitingShipment    = unshippedOrders.Select(p => p.SalesRecordNumber).ToList();

                    view.WaitingPaymentQty = unpaidOrders.Sum(p => p.OrderItems.Sum(s => s.QuantityPurchased));
                    view.WaitingPayment    = unpaidOrders.Select(p => p.SalesRecordNumber).ToList();
                }
            }
        }
Esempio n. 11
0
        private void Update(string code, string status)
        {
            using (berkeleyEntities dataContext = new berkeleyEntities())
            {
                BonanzaListing listing = dataContext.BonanzaListings.Single(p => p.MarketplaceID == _marketplace.ID && p.Code.Equals(code));

                listing.Status = status;

                listing.LastSyncTime = DateTime.UtcNow;

                dataContext.SaveChanges();
            }
        }
Esempio n. 12
0
        private void HowManyOfEachSize()
        {
            using (berkeleyEntities dataContext = new berkeleyEntities())
            {
                dataContext.MaterializeAttributes = true;

                var nikes = dataContext.Items.Where(p => p.SubDescription1.Equals("NIKE") && p.Category.Name.Equals("CLEATS") && p.Quantity > 0).ToList();

                var target = nikes.Where(p => decimal.Parse(p.Dimensions[DimensionName.USMenSize].Value) >= 8 && decimal.Parse(p.Dimensions[DimensionName.USMenSize].Value) <= 12);

                int count = (int)target.Sum(p => p.Quantity);
            }
        }
Esempio n. 13
0
        public void SavePriceDataChanges(IEnumerable <AmazonEnvelopeMessage> msgs)
        {
            using (berkeleyEntities dataContext = new berkeleyEntities())
            {
                foreach (AmazonEnvelopeMessage msg in msgs)
                {
                    Price priceData = (Price)msg.Item;

                    AmznListingItem listingItem = dataContext.AmznListingItems
                                                  .Single(p => p.Item.ItemLookupCode.Equals(priceData.SKU) && p.MarketplaceID == _marketplace.ID && p.IsActive);

                    listingItem.Price = priceData.StandardPrice.Value;
                }

                dataContext.SaveChanges();
            }
        }
Esempio n. 14
0
        //public void SynchronizeListings(int marketplaceID)
        //{
        //    using (berkeleyEntities dataContext = new berkeleyEntities())
        //    {
        //        EbayMarketplace marketplace = dataContext.EbayMarketplaces.Single(p => p.ID == marketplaceID);

        //        ListingSynchronizer synchronizer = new ListingSynchronizer(marketplace, dataContext);

        //        DateTime syncTime = DateTime.UtcNow.AddMinutes(-3);

        //        if (marketplace.ListingSyncTime.HasValue && marketplace.ListingSyncTime.Value > syncTime.AddDays(-2))
        //        {
        //            DateTime from = marketplace.ListingSyncTime.Value.AddMinutes(-5);

        //            synchronizer.SyncByCreatedTime(from, syncTime);

        //            try
        //            {
        //                synchronizer.SyncByModifiedTime(from, syncTime);
        //            }
        //            catch (ApiException e)
        //            {
        //                if (e.Errors.ToArray().Any(p => p.ErrorCode.Equals("21917062")))
        //                {
        //                    synchronizer.SyncActiveListings();
        //                }
        //            }
        //        }
        //        else
        //        {
        //            synchronizer.SyncActiveListings();
        //        }

        //        marketplace.ListingSyncTime = syncTime;

        //        dataContext.SaveChanges();
        //    }
        //}

        //public void SynchronizeOrders(int marketplaceID)
        //{
        //    using (berkeleyEntities dataContext = new berkeleyEntities())
        //    {
        //        EbayMarketplace marketplace = dataContext.EbayMarketplaces.Single(p => p.ID == marketplaceID);

        //        OrderSynchronizer synchronizer = new OrderSynchronizer(marketplace, dataContext);

        //        DateTime syncTime = DateTime.UtcNow.AddMinutes(-3);

        //        DateTime from = marketplace.OrdersSyncTime.HasValue ? marketplace.OrdersSyncTime.Value.AddMinutes(-5) : DateTime.UtcNow.AddDays(-29);

        //        synchronizer.SyncOrdersByModifiedTime(from, syncTime);

        //        marketplace.OrdersSyncTime = syncTime;

        //        dataContext.SaveChanges();
        //    }
        //}

        //public void FixOverpublished(int marketplaceID)
        //{
        //    using (berkeleyEntities dataContext = new berkeleyEntities())
        //    {
        //        EbayMarketplace marketplace = dataContext.EbayMarketplaces.Single(p => p.ID == marketplaceID);

        //        if (!marketplace.ListingSyncTime.HasValue || marketplace.ListingSyncTime.Value < DateTime.UtcNow.AddHours(-1))
        //        {
        //            throw new InvalidOperationException(marketplace.Name + " listings must be synchronized in order to fix overpublished");
        //        }

        //        if (!marketplace.OrdersSyncTime.HasValue || marketplace.OrdersSyncTime.Value < DateTime.UtcNow.AddHours(-1))
        //        {
        //            throw new InvalidOperationException(marketplace.Name + " orders must be synchronized in order to fix overpublished");
        //        }

        //        var listings = dataContext.EbayListings.Where(p => p.Status.Equals(EbayMarketplace.STATUS_ACTIVE) && p.MarketplaceID == marketplace.ID).ToList();

        //        foreach (EbayListing listing in listings.Where(p => !p.ListingItems.Any(s => s.Item == null)))
        //        {

        //            if(listing.Format.Equals(EbayMarketplace.FORMAT_AUCTION))
        //            {
        //                var listingItem = listing.ListingItems.First();

        //                if(listingItem.Item.AuctionCount > listingItem.Item.QtyAvailable)
        //                {
        //                    try
        //                    {
        //                        End(marketplaceID, listing.Code);
        //                    }
        //                    catch (Exception e)
        //                    {
        //                        _logger.Error(e.Message);
        //                    }
        //                }
        //            }
        //            else
        //            {
        //                var listingItems = listing.ListingItems.ToList();

        //                if (listingItems.Any(p => p.Quantity > p.Item.QtyAvailable))
        //                {
        //                    List<ListingItemDto> listingItemDtos = new List<ListingItemDto>();

        //                    foreach (var listingItem in listingItems)
        //                    {
        //                        if (listingItem.Quantity > listingItem.Item.QtyAvailable)
        //                        {
        //                            listingItemDtos.Add(new ListingItemDto() { Sku = listingItem.Item.ItemLookupCode, Qty = listingItem.Item.QtyAvailable, QtySpecified = true });
        //                        }
        //                        else
        //                        {
        //                            listingItemDtos.Add(new ListingItemDto() { Sku = listingItem.Item.ItemLookupCode, Qty = listingItem.Quantity, QtySpecified = true });
        //                        }
        //                    }

        //                    if (listingItemDtos.All(p => p.Qty == 0))
        //                    {
        //                        try
        //                        {
        //                            End(marketplaceID, listing.Code);
        //                        }
        //                        catch (Exception e)
        //                        {
        //                            _logger.Error(e.Message);
        //                        }
        //                    }
        //                    else
        //                    {
        //                        ListingDto listingDto = new ListingDto();
        //                        listingDto.MarketplaceID = marketplaceID;
        //                        listingDto.Code = listing.Code;
        //                        listingDto.Items.AddRange(listingItemDtos);
        //                        listingDto.IsVariation = (bool)listing.IsVariation;


        //                        try
        //                        {
        //                            Revise(listingDto, false, false);
        //                        }
        //                        catch (Exception e)
        //                        {
        //                            _logger.Error(e.Message);
        //                        }

        //                    }

        //                }
        //            }
        //        }
        //    }
        //}


        public void SynchronizeListing(int marketplaceID)
        {
            using (berkeleyEntities dataContext = new berkeleyEntities())
            {
                BonanzaMarketplace marketplace = dataContext.BonanzaMarketplaces.Single(p => p.ID == marketplaceID);

                ListingSynchronizer synchronizer = new ListingSynchronizer(marketplace, dataContext);

                string[] status = new string[] { "for_sale", "ready_to_post", "missing_fields", "sold", "pending_pickup", "reserved" };

                marketplace.ListingSyncTime = DateTime.UtcNow;

                synchronizer.SyncByStatus(status);

                dataContext.SaveChanges();
            }
        }
Esempio n. 15
0
        public void UpdatePrintEntries(IEnumerable <PrintEntry> entries)
        {
            using (berkeleyEntities dataContext = new berkeleyEntities())
            {
                foreach (PrintEntry entry in entries)
                {
                    try
                    {
                        Item item = dataContext.Items.Include("EbayListingItems").Include("AmznListingItems").SingleOrDefault(p => p.ItemLookupCode.Equals(entry.Sku));

                        if (item == null)
                        {
                            continue;
                        }

                        entry.Brand     = item.SubDescription1;
                        entry.ClassName = item.ClassName;
                        entry.Qty       = item.QtyAvailable;
                        entry.Cost      = item.Cost;

                        StringBuilder sb = new StringBuilder();

                        var marketplaces = item.EbayListingItems.GroupBy(p => p.Listing.Marketplace);

                        foreach (var marketplace in marketplaces)
                        {
                            var actives = marketplace.Where(p => p.Listing.Status.Equals("Active"));

                            foreach (var active in actives)
                            {
                                sb.AppendLine(active.ToString());
                            }
                        }

                        entry.Active = sb.ToString();

                        //var ebayHistory = string.Join("<br>",item.EbayListingItems.Select(p => p.ToString()));
                        //var amznHistory = string.Join("<br>", item.AmznListingItems.Select(p => p.ToString()));
                        //entry.History = ebayHistory + "<br>" + amznHistory;
                    }
                    catch (Exception e)
                    {
                    }
                }
            }
        }
Esempio n. 16
0
        public void SaveInventoryDataChanges(IEnumerable <AmazonEnvelopeMessage> msgs)
        {
            using (berkeleyEntities dataContext = new berkeleyEntities())
            {
                foreach (AmazonEnvelopeMessage msg in msgs)
                {
                    Inventory inventoryData = (Inventory)msg.Item;

                    AmznListingItem listingItem = dataContext.AmznListingItems
                                                  .Single(p => p.Item.ItemLookupCode.Equals(inventoryData.SKU) && p.MarketplaceID == _marketplace.ID && p.IsActive);

                    listingItem.Quantity = Convert.ToInt32(inventoryData.Item);
                }

                dataContext.SaveChanges();
            }
        }
Esempio n. 17
0
        private void Update(ListingDto listingDto)
        {
            using (berkeleyEntities dataContext = new berkeleyEntities())
            {
                BonanzaListing listing = dataContext.BonanzaListings.Single(p => p.MarketplaceID == _marketplace.ID && p.Code.Equals(listingDto.Code));

                if (!string.IsNullOrWhiteSpace(listingDto.FullDescription))
                {
                    listing.FullDescription = listingDto.FullDescription;
                }

                if (!string.IsNullOrWhiteSpace(listingDto.Title))
                {
                    listing.Title = listingDto.Title;
                }

                foreach (ListingItemDto listingItemDto in listingDto.Items)
                {
                    Item item = dataContext.Items.Single(p => p.ItemLookupCode.Equals(listingItemDto.Sku));

                    BonanzaListingItem listingItem = listing.ListingItems.SingleOrDefault(p => p.Item.ID == item.ID);

                    if (listingItem == null)
                    {
                        listingItem = new BonanzaListingItem()
                        {
                            Item = item, Listing = listing
                        };
                    }

                    if (listingItemDto.Qty.HasValue)
                    {
                        listingItem.Quantity = listingItemDto.Qty.Value;
                    }

                    if (listingItemDto.Price.HasValue)
                    {
                        listingItem.Price = listingItemDto.Price.Value;
                    }
                }

                listing.LastSyncTime = DateTime.UtcNow;

                dataContext.SaveChanges();
            }
        }
Esempio n. 18
0
        public AmazonEnvelope BuildRelationshipData(IEnumerable <AmznListingItem> listingItems)
        {
            List <AmazonEnvelopeMessage> messages = new List <AmazonEnvelopeMessage>();

            int currentMsg = 1;

            var classGroups = listingItems.Where(p => p.Item.ItemClass != null).GroupBy(p => p.Item.ItemClass.ItemLookupCode);

            using (berkeleyEntities dataContext = new berkeleyEntities())
            {
                foreach (var classGroup in classGroups)
                {
                    var itemClass = dataContext.ItemClasses.SingleOrDefault(p => p.ItemLookupCode.Equals(classGroup.Key));

                    if (itemClass != null)
                    {
                        var siblingSkus = itemClass.ItemClassComponents.Select(p => p.Item)
                                          .Where(p => p.AmznListingItems.Any(s => s.IsActive && s.MarketplaceID == _marketplace.ID))
                                          .Select(p => p.ItemLookupCode);

                        Relationship relationships = new Relationship();
                        relationships.ParentSKU = classGroup.Key;

                        List <RelationshipRelation> relations = new List <RelationshipRelation>();

                        foreach (string sku in siblingSkus)
                        {
                            relations.Add(new RelationshipRelation()
                            {
                                SKU = sku, Type = RelationshipRelationType.Variation
                            });
                        }

                        relationships.Relation = relations.ToArray();

                        messages.Add(BuildMessage(relationships, currentMsg));

                        currentMsg++;
                    }
                }
            }

            return(BuildEnvelope(AmazonEnvelopeMessageType.Relationship, messages));
        }
Esempio n. 19
0
        private static void FixOverpublished()
        {
            using (berkeleyEntities dataContext = new berkeleyEntities())
            {
                foreach (AmznMarketplace marketplace in dataContext.AmznMarketplaces)
                {
                    _amznServices.FixOverpublished(marketplace.ID);

                    _logger.Info(marketplace.Name + " fixing overpublished completed");
                }

                foreach (EbayMarketplace marketplace in dataContext.EbayMarketplaces)
                {
                    _ebayServices.FixOverpublished(marketplace.ID);

                    _logger.Info(marketplace.Name + " fixing overpublished completed");
                }
            }
        }
Esempio n. 20
0
        public List <AmznListingItem> SaveProductDataChanges(IEnumerable <AmazonEnvelopeMessage> msgs)
        {
            var added = _dataContext.ObjectStateManager.GetObjectStateEntries(EntityState.Added).Select(p => p.Entity).Cast <AmznListingItem>();

            List <AmznListingItem> listingItems = new List <AmznListingItem>();

            using (berkeleyEntities dataContext = new berkeleyEntities())
            {
                foreach (var msg in msgs)
                {
                    Product product = (Product)msg.Item;

                    if (dataContext.Items.Any(p => p.ItemLookupCode.Equals(product.SKU)))
                    {
                        AmznListingItem listingItem = dataContext.AmznListingItems
                                                      .SingleOrDefault(p => p.Item.ItemLookupCode.Equals(product.SKU) && p.MarketplaceID == _marketplace.ID);

                        listingItems.Add(added.Single(p => p.Item.ItemLookupCode.Equals(product.SKU)));

                        if (listingItem == null)
                        {
                            listingItem              = new AmznListingItem();
                            listingItem.Item         = dataContext.Items.Single(p => p.ItemLookupCode.Equals(product.SKU));
                            listingItem.Sku          = product.SKU;
                            listingItem.Marketplace  = dataContext.AmznMarketplaces.Single(p => p.ID == _marketplace.ID);
                            listingItem.OpenDate     = DateTime.UtcNow;
                            listingItem.LastSyncTime = DateTime.UtcNow;
                            listingItem.ASIN         = "UNKNOWN";
                            listingItem.Quantity     = 0;
                            listingItem.Price        = 0;
                            listingItem.Title        = product.DescriptionData.Title;
                        }

                        listingItem.IsActive = true;
                    }
                }

                dataContext.SaveChanges();
            }

            return(listingItems);
        }
        public IEnumerable <MarketplaceView> GetAllMarketplaceViews()
        {
            List <MarketplaceView> views = new List <MarketplaceView>();

            using (_dataContext = new berkeleyEntities())
            {
                foreach (EbayMarketplace marketplace in _dataContext.EbayMarketplaces)
                {
                    views.Add(CreateMarketplaceView(marketplace));
                }


                foreach (AmznMarketplace marketplace in _dataContext.AmznMarketplaces)
                {
                    views.Add(CreateMarketplaceView(marketplace));
                }
            }

            return(views);
        }
Esempio n. 22
0
        public void bckWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            _proxy     = new Mage_Api_Model_Server_V2_HandlerPortTypeClient();
            _sessionID = _proxy.login("berkeleyJuan", "genesis13");
            _catalogProductFactories.ForEach(p => p.Initiliaze(_proxy, _sessionID));

            using (berkeleyEntities dataContext = new berkeleyEntities())
            {
                var posts = dataContext.bsi_posts.Where(p => p.marketplace == 512 && p.status == 10 && p.purchaseOrder.Equals(_currentWorkOrder)).ToList();

                double processed    = 0;
                double totalPending = posts.Count();
                _succesfulUploads = 0;
                _errorCount       = 0;

                if (totalPending > 0)
                {
                    foreach (bsi_posts post in posts)
                    {
                        try
                        {
                            CreateOrUpdateCatalogProduct(post);
                            _succesfulUploads += post.bsi_quantities.Count;
                            post.status        = 0;
                        }
                        catch (NotImplementedException ex)
                        {
                            foreach (bsi_quantities postItem in post.bsi_quantities)
                            {
                                _errorCount++;
                                this.Log(postItem.itemLookupCode + ": " + ex.Message);
                            }
                        }
                        dataContext.SaveChanges();
                        processed++;
                        _bckWorker.ReportProgress((int)((processed / totalPending) * 100));
                    }
                }
            }
        }
        private string GetParentTitle(EbayEntry entry)
        {
            string title = entry.Title;

            using (berkeleyEntities dataContext = new berkeleyEntities())
            {
                dataContext.MaterializeAttributes = true;

                Item item = dataContext.Items.Single(p => p.ItemLookupCode.Equals(entry.Sku));

                var wordsToRemove = item.Dimensions.Select(p => p.Key.ToString()).Concat(item.Dimensions.Select(p => p.Value.Value.ToString()));

                foreach (string word in wordsToRemove)
                {
                    title = title.Replace(" " + word + " ", " ");
                }

                title = title.Replace("Size", "");
            }

            return(title);
        }
Esempio n. 24
0
        private void btnUpdateBin_Click(object sender, EventArgs e)
        {
            List <BinData> bins = new List <BinData>();

            using (berkeleyEntities dataContext = new berkeleyEntities())
            {
                var entries = dataContext.InventoryEntries.Where(p => p.PhysicalInventory.Code.Equals(_inventoryRef)).ToList();

                var entryGroups = entries.GroupBy(p => p.Item);

                foreach (var entryGroup in entryGroups)
                {
                    BinData bin = new BinData();
                    bin.Sku = entryGroup.Key.ItemLookupCode;

                    var binGroups = entryGroup.GroupBy(p => p.Bin);

                    StringBuilder sb = new StringBuilder();

                    foreach (var binGroup in binGroups)
                    {
                        if (binGroup.Sum(s => s.Counted) > 0)
                        {
                            sb.AppendLine(binGroup.Key + "(" + binGroup.Sum(s => s.Counted) + ") ");
                        }
                    }

                    bin.Bin = sb.ToString();

                    bins.Add(bin);
                }
            }

            SaveFileDialog sfd = new SaveFileDialog();

            sfd.ShowDialog();

            GenerateExcelFile(sfd.FileName, bins);
        }
Esempio n. 25
0
        private void btnSetWorkbook_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Multiselect      = false;
            ofd.ValidateNames    = true;
            ofd.DereferenceLinks = false; // Will return .lnk in shortcuts.
            ofd.Filter           = "Excel |*.xlsx";

            if ((bool)ofd.ShowDialog())
            {
                lbCurrentWorkbook.Content = ofd.FileName;

                using (berkeleyEntities dataContext = new berkeleyEntities())
                {
                    _workbook = new ExcelWorkbook(ofd.FileName);

                    CompositeCollection composite = new CompositeCollection();

                    foreach (var marketplace in dataContext.EbayMarketplaces)
                    {
                        composite.Add(new EbayPublisherViewModel(_workbook, marketplace.Code));
                    }

                    foreach (var marketplace in dataContext.AmznMarketplaces)
                    {
                        composite.Add(new AmznPublisherViewModel(_workbook, marketplace.Code));
                    }

                    foreach (var marketplace in dataContext.BonanzaMarketplaces)
                    {
                        composite.Add(new BonanzaPublisherViewModel(_workbook, marketplace.Code));
                    }

                    tcSheets.ItemsSource = composite;
                }
            }
        }
Esempio n. 26
0
        private void btnLoadPending_Click(object sender, EventArgs e)
        {
            pendingWorkOrderBindingSource.DataSource = null;
            _pendingWorkOrders = new List <PendingWorkOrder>();

            using (berkeleyEntities dataContext = new berkeleyEntities())
            {
                var pendingWorkOrders = dataContext.bsi_posts
                                        .Where(p => p.status == 10 && p.marketplace == 512)
                                        .Select(p => new { WorkOrder = p.purchaseOrder, User = p.listUser }).Distinct();

                foreach (var wo in pendingWorkOrders)
                {
                    PendingWorkOrder pwo = new PendingWorkOrder(wo.WorkOrder, wo.User);
                    pwo.PendingCount = dataContext.bsi_posts.Where(p => p.status == 10 && p.purchaseOrder.Equals(wo.WorkOrder) && p.marketplace == 512).SelectMany(p => p.bsi_quantities).Count();
                    pwo.TotalCount   = dataContext.bsi_posts.Where(p => p.purchaseOrder.Equals(wo.WorkOrder) && p.marketplace == 512).SelectMany(p => p.bsi_quantities).Count();
                    _pendingWorkOrders.Add(pwo);
                }


                pendingWorkOrderBindingSource.DataSource = _pendingWorkOrders;
            }
        }
Esempio n. 27
0
            private void PublishEntries(IEnumerable <BonanzaEntry> entries)
            {
                using (_dataContext = new berkeleyEntities())
                {
                    _marketplace = _dataContext.BonanzaMarketplaces.Single(p => p.Code.Equals(_marketplaceCode));

                    var update = entries.Where(p => !string.IsNullOrWhiteSpace(p.Code)).GroupBy(p => p.Code);

                    foreach (var group in update)
                    {
                        BonanzaListing listing = _marketplace.Listings.Single(p => p.Code.Equals(group.Key));

                        TryUpdateListing(listing, group);
                    }

                    var create = entries.Where(p => string.IsNullOrWhiteSpace(p.Code)).GroupBy(p => p.ClassName);

                    foreach (var group in create)
                    {
                        TryCreateListing(group);
                    }
                }
            }
Esempio n. 28
0
        private static void SyncEbayAndAmznOrders()
        {
            using (berkeleyEntities dataContext = new berkeleyEntities())
            {
                foreach (AmznMarketplace marketplace in dataContext.AmznMarketplaces)
                {
                    _amznServices.SynchronizeOrders(marketplace.ID);

                    _logger.Info(marketplace.Name + " order synchronization completed");
                }

                foreach (EbayMarketplace marketplace in dataContext.EbayMarketplaces)
                {
                    _ebayServices.SynchronizeListings(marketplace.ID);

                    _logger.Info(marketplace.Name + " listing synchronization completed");

                    _ebayServices.SynchronizeOrders(marketplace.ID);

                    _logger.Info(marketplace.Name + " order synchronization completed");
                }
            }
        }
        private void PublishEntries(IEnumerable <EbayEntry> entries)
        {
            var pendingEntries = entries.Cast <EbayEntry>();

            using (_dataContext = new berkeleyEntities())
            {
                _marketplace = _dataContext.EbayMarketplaces.Single(p => p.Code.Equals(_marketplaceCode));

                var update = entries.Where(p => !string.IsNullOrWhiteSpace(p.Code)).GroupBy(p => p.Code);

                foreach (var entryGroup in update)
                {
                    EbayListing listing = _marketplace.Listings.Single(p => p.Code.Equals(entryGroup.Key));

                    TryUpdateListing(listing, entryGroup);
                }

                var pendingCreate = entries.Where(p => string.IsNullOrWhiteSpace(p.Code));

                var individuals = pendingCreate.Where(p => !p.IsVariation());
                var variations  = pendingCreate.Where(p => p.IsVariation()).GroupBy(p => p.ClassName);

                foreach (var entryGroup in variations)
                {
                    TryCreateListing(entryGroup, true);
                }

                foreach (var entry in individuals)
                {
                    TryCreateListing(new List <EbayEntry>()
                    {
                        entry
                    }, false);
                }
            }
        }
Esempio n. 30
0
        private List <ReportProductView> GetProductData()
        {
            List <ReportProductView> products = new List <ReportProductView>();

            using (berkeleyEntities dataContext = new berkeleyEntities())
            {
                //var items = dataContext.Items.Include("AmznListingItems.OrderItems.Order").Include("EbayListingItems.OrderItems.Order")
                //    .Where(p => !p.Inactive &&
                //        !p.DepartmentName.Equals("APPAREL") &&
                //        !p.DepartmentName.Equals("ACCESSORIES") &&
                //        !p.DepartmentName.Equals("MIXED ITEMS & LOTS")).ToList()
                //        .Where(p => p.Quantity > 0 || p.OnActiveListing > 0);

                dataContext.CommandTimeout = 0;

                var items = dataContext.Items
                            .Include("AmznListingItems.OrderItems.Order")
                            .Include("EbayListingItems.OrderItems.Order")
                            .ToList().Where(p =>
                                            (p.Quantity > 0 || p.OnActiveListing > 0 || p.OnPendingOrder > 0) &&
                                            !p.Inactive &&
                                            !p.DepartmentName.Equals("APPAREL") &&
                                            !p.DepartmentName.Equals("ACCESSORIES") &&
                                            !p.DepartmentName.Equals("MIXED ITEMS & LOTS"));

                foreach (BerkeleyEntities.Item item in items)
                {
                    ReportProductView product = new ReportProductView(item.ItemLookupCode);

                    if (item.SupplierLists.Any())
                    {
                        product.Supplier = item.SupplierLists.First().Supplier.SupplierName;
                    }
                    else
                    {
                        product.Supplier = "NONE";
                    }

                    product.Brand          = item.SubDescription1;
                    product.Cost           = item.Cost;
                    product.Department     = item.DepartmentName;
                    product.OnPO           = item.OnPurchaseOrder;
                    product.OnHand         = (int)item.Quantity;
                    product.OnHold         = item.OnHold;
                    product.OnPendingOrder = item.OnPendingOrder;

                    product.OrgQty = item.AmznListingItems.Where(p => p.MarketplaceID == 1 && p.IsActive).Sum(p => p.Quantity);
                    product.StgQty = item.EbayListingItems.Where(p => p.Listing.MarketplaceID == 1 && p.Listing.Status.Equals("Active")).Sum(p => p.Quantity);
                    product.OmsQty = item.EbayListingItems.Where(p => p.Listing.MarketplaceID == 2 && p.Listing.Status.Equals("Active")).Sum(p => p.Quantity);
                    product.SavQty = item.EbayListingItems.Where(p => p.Listing.MarketplaceID == 3 && p.Listing.Status.Equals("Active")).Sum(p => p.Quantity);

                    var ebayDuplicates = item.EbayListingItems
                                         .Where(p => p.Listing.Status.Equals("Active"))
                                         .GroupBy(p => new { Marketplace = p.Listing.Marketplace, Format = p.Listing.Format })
                                         .Where(p => p.Count() > 1);

                    if (ebayDuplicates.Count() > 0)
                    {
                        product.Duplicates = string.Join(" ", ebayDuplicates.Select(p => p.Count().ToString() + p.Key.Marketplace.Code));
                    }
                    else
                    {
                        product.Duplicates = string.Empty;
                    }

                    product.StgPending = item.EbayListingItems.Where(p => p.Listing.MarketplaceID == 1)
                                         .SelectMany(p => p.OrderItems).Where(p => p.Order.IsWaitingForPayment() || p.Order.IsWaitingForShipment())
                                         .Sum(p => p.QuantityPurchased);

                    product.OmsPending = item.EbayListingItems.Where(p => p.Listing.MarketplaceID == 2)
                                         .SelectMany(p => p.OrderItems).Where(p => p.Order.IsWaitingForPayment() || p.Order.IsWaitingForShipment())
                                         .Sum(p => p.QuantityPurchased);

                    product.SavPending = item.EbayListingItems.Where(p => p.Listing.MarketplaceID == 3)
                                         .SelectMany(p => p.OrderItems).Where(p => p.Order.IsWaitingForPayment() || p.Order.IsWaitingForShipment())
                                         .Sum(p => p.QuantityPurchased);

                    product.OrgPending = item.AmznListingItems.Where(p => p.MarketplaceID == 1)
                                         .SelectMany(p => p.OrderItems).Where(p => p.Order.Status.Equals("Unshipped") || p.Order.Status.Equals("Pending"))
                                         .Sum(p => p.QuantityOrdered);

                    product.StgSold = item.EbayListingItems.Where(p => p.Listing.MarketplaceID == 1)
                                      .SelectMany(p => p.OrderItems).Where(p => p.Order.MarkedAsShipped()).Sum(p => p.QuantityPurchased);
                    product.OmsSold = item.EbayListingItems.Where(p => p.Listing.MarketplaceID == 2)
                                      .SelectMany(p => p.OrderItems).Where(p => p.Order.MarkedAsShipped()).Sum(p => p.QuantityPurchased);
                    product.SavSold = item.EbayListingItems.Where(p => p.Listing.MarketplaceID == 3)
                                      .SelectMany(p => p.OrderItems).Where(p => p.Order.MarkedAsShipped()).Sum(p => p.QuantityPurchased);
                    product.OrgSold = item.AmznListingItems.Where(p => p.MarketplaceID == 1)
                                      .SelectMany(p => p.OrderItems).Where(p => p.Order.Status.Equals("Shipped")).Sum(p => p.QuantityOrdered);

                    products.Add(product);
                }
            }

            return(products);
        }