private void OnUploadFile(object sender, EventArgs args)
    {
        TryInitByForm();

        if ((fileElem.PostedFile != null) && (fileElem.PostedFile.ContentLength > 0))
        {
            int skuFileId = ProcessUploadForNewEproduct();
            if (skuFileId > 0)
            {
                // Update product with number of uploaded files (for new product it is one file)
                SKUInfo newProduct = SKUInfoProvider.GetSKUInfo(SKUID);
                newProduct.SetValue("SKUEProductFilesCount", 1);
                newProduct.Update();

                ShowChangesSaved();
            }
            else
            {
                ShowError(ErrorMessage);
            }
        }
    }
    /// <summary>
    /// Changes SKU option from data set to attribute option. Attribute is an option and it does not need product data like for example itinerary.
    /// </summary>
    /// <param name="options">Data set with product option</param>
    private void ChangeProductToAttribute(DataSet options)
    {
        if (DataHelper.DataSourceIsEmpty(options))
        {
            return;
        }

        foreach (DataRow option in options.Tables[0].Rows)
        {
            SKUInfo product = new SKUInfo(option);

            product.SKUProductType = SKUProductTypeEnum.Product;
            product.SetValue("SKUTrackInventory", null);
            product.SetValue("SKUMaxItemsInOrder", null);
            product.SetValue("SKUMinItemsInOrder", null);
            product.SetValue("SKUAvailableItems", null);
            product.SetValue("SKUValidity", null);
            product.SetValue("SKUReorderAt", null);
            product.SetValue("SKUDescription", null);
            product.SetValue("SKUAvailableInDays", null);
            product.SetValue("SKUNumber", null);
            product.SetValue("SKUMaxDownloads", null);
            product.SetValue("SKUMaxPrice", null);
            product.SetValue("SKUMinPrice", null);
            product.SetValue("SKUValidFor", null);
            product.SetValue("SKURetailPrice", null);
            product.SetValue("SKUEproductFilesCount", null);
            product.SKUDepartmentID = 0;
            product.SKUManufacturerID = 0;
            product.SKUInternalStatusID = 0;
            product.SKUPublicStatusID = 0;
            product.SKUSupplierID = 0;
            product.SKUImagePath = null;
            product.SKUWeight = 0;
            product.SKUWidth = 0;
            product.SKUDepth = 0;
            product.SKUHeight = 0;
            product.SKUSellOnlyAvailable = false;
            product.SKUPrivateDonation = false;
            product.SKUNeedsShipping = false;
            product.SKUValidUntil = DateTimeHelper.ZERO_TIME;
            product.SKUMembershipGUID = Guid.Empty;
            product.SKUConversionName = null;
            product.SKUConversionValue = "";
            product.SKUBundleInventoryType = 0;
            product.SKUParentSKUID = 0;
            product.SKUShortDescription = null;

            SKUInfoProvider.SetSKUInfo(product);
        }
    }
Exemplo n.º 3
0
        /// <summary>
        /// For saving the product
        /// </summary>
        private void SaveProduct()
        {
            string       imagePath = string.Empty;
            TreeProvider tree      = new TreeProvider(MembershipContext.AuthenticatedUser);

            CMS.DocumentEngine.TreeNode parentPage = tree.SelectNodes()
                                                     .Path(folderpath)
                                                     .OnCurrentSite()
                                                     .Culture(DocumentContext.CurrentDocument.DocumentCulture)
                                                     .FirstObject;
            if (parentPage != null)
            {
                CampaignsProduct products = new CampaignsProduct()
                {
                    QtyPerPack     = ValidationHelper.GetInteger(txtBundleQnt.Text, default(int)),
                    BrandID        = ValidationHelper.GetInteger(ddlBrand.SelectedValue, default(int)),
                    EstimatedPrice = ValidationHelper.GetDouble(txtEstPrice.Text, default(double)),
                    State          = ValidationHelper.GetInteger(ddlState.SelectedValue, default(int)),
                    CategoryID     = ValidationHelper.GetInteger(ddlProdCategory.SelectedValue, default(int)),
                    ProductName    = ValidationHelper.GetString(txtShortDes.Text, string.Empty)
                };
                if (productImage.HasFile)
                {
                    imagePath = UploadImage.UploadImageToMeadiaLibrary(productImage, libraryFolderName);
                }
                SKUInfo newSkuProduct = new SKUInfo()
                {
                    SKUName           = ValidationHelper.GetString(txtShortDes.Text, string.Empty),
                    SKUNumber         = ValidationHelper.GetString("00000", string.Empty),
                    SKUDescription    = ValidationHelper.GetString(txtLongDes.Text, string.Empty),
                    SKUPrice          = ValidationHelper.GetDouble(txtActualPrice.Text, default(double)),
                    SKUEnabled        = ValidationHelper.GetBoolean(ddlStatus.SelectedValue, false),
                    SKUAvailableItems = ValidationHelper.GetInteger(txtQuantity.Text, 0),
                    SKUImagePath      = ValidationHelper.GetString(imagePath, string.Empty),
                    SKUSiteID         = CurrentSite.SiteID,
                    SKUProductType    = SKUProductTypeEnum.EProduct,
                    SKUWeight         = ValidationHelper.GetDouble(txtWeight.Text, default(double))
                };
                if (!string.IsNullOrEmpty(txtExpDate.Text))
                {
                    newSkuProduct.SKUValidUntil = ValidationHelper.GetDateTime(txtExpDate.Text, DateTime.Now);
                }
                newSkuProduct.SetValue("SKUProductCustomerReferenceNumber", ValidationHelper.GetString(ddlPosNo.SelectedValue, string.Empty));
                products.DocumentName    = ValidationHelper.GetString(txtShortDes.Text, string.Empty);
                products.DocumentCulture = CurrentDocument.DocumentCulture;
                SKUInfoProvider.SetSKUInfo(newSkuProduct);
                products.NodeSKUID = newSkuProduct.SKUID;
                PageTemplateInfo template = PageTemplateInfoProvider.GetPageTemplateInfo(SettingsKeyInfoProvider.GetValue("KDA_InventoryProductPageTemplateName", CurrentSiteName));
                if (template != null)
                {
                    products.DocumentPageTemplateID = template.PageTemplateId;
                }
                products.Insert(parentPage, true);
                var productID = ValidationHelper.GetInteger(products.CampaignsProductID, 0);
                AllocateProductToUsers(productID);
                lblSuccessMsg.Visible  = true;
                lblFailureText.Visible = false;
                EmptyFields(true);
                Response.Cookies["status"].Value    = QueryStringStatus.Added;
                Response.Cookies["status"].HttpOnly = false;
                URLHelper.Redirect($"{CurrentDocument.Parent.DocumentUrlPath}?status={QueryStringStatus.Added}");
            }
            else
            {
                lblFailureText.Visible = true;
            }
        }
Exemplo n.º 4
0
    /// <summary>
    /// Changes SKU option from data set to attribute option. Attribute is an option and it does not need product data like for example itinerary.
    /// </summary>
    /// <param name="options">Data set with product option</param>
    private void ChangeProductToAttribute(DataSet options)
    {
        if (DataHelper.DataSourceIsEmpty(options))
        {
            return;
        }

        foreach (DataRow option in options.Tables[0].Rows)
        {
            SKUInfo product = new SKUInfo(option);

            product.SKUProductType = SKUProductTypeEnum.Product;
            product.SetValue("SKUTrackInventory", null);
            product.SetValue("SKUMaxItemsInOrder", null);
            product.SetValue("SKUMinItemsInOrder", null);
            product.SetValue("SKUAvailableItems", null);
            product.SetValue("SKUValidity", null);
            product.SetValue("SKUReorderAt", null);
            product.SetValue("SKUDescription", null);
            product.SetValue("SKUAvailableInDays", null);
            product.SetValue("SKUNumber", null);
            product.SetValue("SKUValidFor", null);
            product.SetValue("SKURetailPrice", null);
            product.SetValue("SKUEproductFilesCount", null);
            product.SKUDepartmentID        = 0;
            product.SKUManufacturerID      = 0;
            product.SKUBrandID             = 0;
            product.SKUCollectionID        = 0;
            product.SKUTaxClassID          = 0;
            product.SKUInternalStatusID    = 0;
            product.SKUPublicStatusID      = 0;
            product.SKUSupplierID          = 0;
            product.SKUImagePath           = null;
            product.SKUWeight              = 0;
            product.SKUWidth               = 0;
            product.SKUDepth               = 0;
            product.SKUHeight              = 0;
            product.SKUSellOnlyAvailable   = false;
            product.SKUNeedsShipping       = false;
            product.SKUValidUntil          = DateTimeHelper.ZERO_TIME;
            product.SKUMembershipGUID      = Guid.Empty;
            product.SKUBundleInventoryType = 0;
            product.SKUParentSKUID         = 0;
            product.SKUShortDescription    = null;

            SKUInfo.Provider.Set(product);
        }
    }
    /// <summary>
    /// Insert product data to database
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string imagePath = string.Empty;

        try
        {
            int programID = ValidationHelper.GetInteger(ddlProgram.SelectedValue, default(int));
            if (programID != default(int))
            {
                Program      program    = new Program();
                TreeProvider tree       = new TreeProvider(MembershipContext.AuthenticatedUser);
                var          programDoc = ProgramProvider.GetPrograms()
                                          .WhereEquals("NodeSiteID", CurrentSite.SiteID)
                                          .Columns("NodeID")
                                          .WhereEquals("ProgramID", programID)
                                          .FirstOrDefault();
                if (!DataHelper.DataSourceIsEmpty(programDoc))
                {
                    int programNodeID = programDoc.NodeID;
                    var document      = DocumentHelper.GetDocument(programNodeID, CurrentDocument.DocumentCulture, tree);
                    var createNode    = tree.SelectSingleNode(SiteContext.CurrentSiteName, document.NodeAliasPath, CurrentDocument.DocumentCulture);
                    if (createNode != null)
                    {
                        string itemSpecsID, customItemSpecs;
                        GetItemSpecsValue(out itemSpecsID, out customItemSpecs);
                        CampaignsProduct products = new CampaignsProduct()
                        {
                            ProgramID       = ValidationHelper.GetInteger(ddlProgram.SelectedValue, default(int)),
                            EstimatedPrice  = ValidationHelper.GetDouble(txtEstimatedprice.Text, default(double)),
                            BrandID         = ValidationHelper.GetInteger(hfBrandItemID.Value, default(int)),
                            CategoryID      = ValidationHelper.GetInteger(ddlProductcategory.SelectedValue, default(int)),
                            QtyPerPack      = ValidationHelper.GetInteger(txtQty.Text, default(int)),
                            ItemSpecs       = ValidationHelper.GetString(itemSpecsID, string.Empty),
                            CustomItemSpecs = ValidationHelper.GetString(customItemSpecs, string.Empty),
                            State           = ValidationHelper.GetInteger(ddlState.SelectedValue, default(int)),
                            ProductName     = ValidationHelper.GetString(txtProductName.Text, string.Empty)
                        };
                        products.DocumentName    = ValidationHelper.GetString(txtProductName.Text, string.Empty);
                        products.DocumentCulture = CurrentDocument.DocumentCulture;
                        if (productImage.HasFile)
                        {
                            string libraryFolderName = SettingsKeyInfoProvider.GetValue(CurrentSite.SiteName + ".KDA_ImagesFolderName");
                            imagePath = UploadImage.UploadImageToMeadiaLibrary(productImage, libraryFolderName);
                        }
                        SKUInfo newProduct = new SKUInfo()
                        {
                            SKUName             = ValidationHelper.GetString(txtProductName.Text, string.Empty),
                            SKUNumber           = ValidationHelper.GetString("00000", string.Empty),
                            SKUShortDescription = ValidationHelper.GetString(txtProductName.Text, string.Empty),
                            SKUDescription      = ValidationHelper.GetString(txtLongDescription.Text, string.Empty),
                            SKUEnabled          = ValidationHelper.GetString(ddlStatus.SelectedValue, "1") == "1" ? true : false,
                            SKUImagePath        = imagePath,
                            SKUSiteID           = CurrentSite.SiteID,
                            SKUProductType      = SKUProductTypeEnum.EProduct,
                            SKUPrice            = 0
                        };
                        if (!string.IsNullOrEmpty(txtExpireDate.Text))
                        {
                            newProduct.SKUValidUntil = ValidationHelper.GetDateTime(txtExpireDate.Text, DateTime.MinValue);
                        }
                        newProduct.SetValue("SKUProductCustomerReferenceNumber", ValidationHelper.GetString(ddlPos.SelectedValue, string.Empty));
                        SKUInfoProvider.SetSKUInfo(newProduct);
                        products.NodeSKUID = newProduct.SKUID;
                        products.Insert(createNode, true);
                        int capaignNodeID = ValidationHelper.GetInteger(Request.QueryString["camp"], default(int));
                        var campDoc       = DocumentHelper.GetDocument(capaignNodeID, CurrentDocument.DocumentCulture, tree);
                        if (campDoc != null)
                        {
                            Response.Redirect($"{campDoc.DocumentUrlPath}?status={QueryStringStatus.Added}");
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            EventLogProvider.LogException("CMSWebParts_Kadena_Campaign_Web_Form_AddCampaignProducts", "btnSave_Click", ex, CurrentSite.SiteID, ex.Message);
        }
    }