예제 #1
0
        private void btn_product_delete_Click(object sender, EventArgs e)
        {
            var product = new Four51WebProduct(txt_sharedsecret.Text, txt_serviceid.Text)
            {
                InteropID = txt_product_interopid.Text
            };

            try
            {
                product.Delete();
                MessageBox.Show("Deleted: " + product.InteropID);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #2
0
        private void btn_product_save_Click(object sender, EventArgs e)
        {
            var product = new Four51WebProduct(txt_sharedsecret.Text, txt_serviceid.Text)
            {
                InteropID                                                                  = txt_product_interopid.Text,
                NewInteropID                                                               = txt_product_newinteropid.Text,
                ID                                                                         = txt_product_productid.Text,
                Name                                                                       = txt_product_name.Text,
                UNSPSC                                                                     = txt_product_unspsc.Text,
                UnitOfMeasure                                                              = txt_product_unitofmeasure.Text,
                Description                                                                = txt_product_description.Text,
                Type                                                                       = ddl_product_type.SelectedItem != null?ddl_product_type.SelectedItem.To <string>().Replace(" ", "").To <ProductType>() : ProductType.Static,
                                                              StandardOrders               = chk_product_standardorders.Checked,
                                                              ReplenishmentOrders          = chk_product_replenishmentorders.Checked,
                                                              PriceRequests                = chk_product_pricerequests.Checked,
                                                              QuantityMultiplier           = txt_product_quantitymultiplier.Text.To <int>(),
                                                              ShipWeight                   = txt_product_shipweight.Text.To <decimal>(),
                                                              TrackInventory               = chk_product_trackinventory.Checked,
                                                              AllowOrdersToExceedInventory = chk_product_allowexceed.Checked,
                                                              InventoryNotificationPoint   = txt_product_inventorynotification.Text.To <int>(),
                                                              AvailableQuantity            = txt_product_quantity.Text.To <int>(),
                                                              DisplayInventoryToBuyer      = chk_product_displayinventory.Checked,
                                                              Active                       = chk_product_active.Checked,
                                                              LargeImage                   = openLargeImage.FileName.Length > 0 ? new Four51WebProductImage(openLargeImage.FileName) : null,
                                                              SmallImage                   = openSmallImage.FileName.Length > 0 ? new Four51WebProductImage(openSmallImage.FileName) : null
            };

            foreach (DataGridViewRow row in grid_variants.Rows)
            {
                if (row.Cells[0].Value == null)
                {
                    break;
                }
                product.Variants.Add(new Four51WebVariant(txt_sharedsecret.Text, txt_serviceid.Text)
                {
                    InteropID                   = row.Cells[2].Value.To <string>(),
                    NewInteropID                = row.Cells[1].Value.To <string>(),
                    ID                          = row.Cells[0].Value.To <string>(),
                    Description                 = row.Cells[3].Value.To <string>(),
                    Active                      = row.Cells[5].Value.To <bool>(),
                    Image                       = row.Cells["FileName"].To <string>().IsNullOrWhiteSpace() ? null : new Four51WebProductImage(row.Cells["FileName"].Value.To <string>()),
                    AvailableQuantity           = row.Cells[6].Value.To <int>(),
                    DecrementByReservedQuantity = row.Cells[7].Value.To <bool>(),
                    ProductInteropID            = txt_product_interopid.Text
                });
            }

            foreach (DataGridViewRow row in grid_priceschedules.Rows)
            {
                if (row.Cells[0].Value == null)
                {
                    break;
                }
                product.PriceSchedules.Add(new Four51WebPriceSchedule(txt_sharedsecret.Text, txt_serviceid.Text)
                {
                    ProductInteropID            = txt_product_interopid.Text,
                    Name                        = row.Cells[0].Value.To <string>(),
                    MinimumQuantity             = row.Cells[1].Value.To <int>(),
                    MaximumQuantity             = row.Cells[2].Value.To <int>(),
                    OrderType                   = (Four51.APISDK.Four51Product.OrderType)Enum.Parse(typeof(Four51.APISDK.Four51Product.OrderType), row.Cells[3].Value.To <string>()),
                    ApplySalesTax               = row.Cells[4].Value.To <bool>(),
                    ApplyShipping               = row.Cells[5].Value.To <bool>(),
                    RestrictedQuantitySelection = row.Cells[6].Value.To <bool>(),
                    UseCumulativeQuantity       = row.Cells[7].Value.To <bool>()
                });

                if (row.Cells[10].Value.To <string>().Length > 0)
                {
                    product.PriceScheduleAssignments.Add(new Four51WebPriceScheduleAssignment(txt_sharedsecret.Text, txt_serviceid.Text)
                    {
                        ProductInteropID               = row.Cells[8].Value.To <string>() == txt_product_interopid.Text ? product.InteropID : null,
                        VariantInteropID               = row.Cells[8].Value.To <string>() == txt_product_interopid.Text ? null :  row.Cells[8].Value.To <string>(),
                        BuyerCompanyInteropID          = txt_product_companyinteropid.Text,
                        AssignmentLevel                = row.Cells[9].Value.To <PartyType>(),
                        PartyInteropID                 = row.Cells[10].Value.To <string>(),
                        StandardOrderScheduleName      = row.Cells[3].Value.To <Four51.APISDK.Four51Product.OrderType>() == Four51.APISDK.Four51Product.OrderType.Standard ? row.Cells[0].Value.To <string>() : null,
                        ReplenishmentOrderScheduleName = row.Cells[3].Value.To <Four51.APISDK.Four51Product.OrderType>() == Four51.APISDK.Four51Product.OrderType.Replenishment ? row.Cells[0].Value.To <string>() : null,
                        PriceRequestOrderScheduleName  = row.Cells[3].Value.To <Four51.APISDK.Four51Product.OrderType>() == Four51.APISDK.Four51Product.OrderType.PriceRequest ? row.Cells[0].Value.To <string>() : null
                    });
                }

                foreach (DataGridViewRow rw in grid_pricebreaks.Rows)
                {
                    if (rw.Cells[0].Value == null)
                    {
                        break;
                    }
                    product.PriceSchedules.Last().PriceBreaks.Add(new Four51WebPriceBreak()
                    {
                        Price    = rw.Cells[0].Value.To <decimal>(),
                        Quantity = rw.Cells[1].Value.To <int>()
                    });
                }
            }
            ;

            try
            {
                product.Save();
                MessageBox.Show("Saved: " + product.ID);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }