/// <summary>
    /// Gets object from the specified column of the supplier with specific ID.
    /// </summary>
    /// <param name="Id">Supplier ID</param>
    /// <param name="column">Column name</param>
    public static object GetSupplier(object Id, string column)
    {
        int id = ValidationHelper.GetInteger(Id, 0);

        if ((id > 0) && !DataHelper.IsEmpty(column))
        {
            // Get supplier
            SupplierInfo si = SupplierInfoProvider.GetSupplierInfo(id);

            if (si != null)
            {
                // Return datarow value if specified column exists
                if (si.ContainsColumn(column))
                {
                    return(si.GetValue(column));
                }
                else
                {
                    return("");
                }
            }
        }

        return("");
    }
Beispiel #2
0
    /// <summary>
    /// Sets the data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Check module permissions
        bool global = (editedSiteId <= 0);

        if (!ECommerceContext.IsUserAuthorizedToModifySupplier(global))
        {
            if (global)
            {
                RedirectToAccessDenied("CMS.Ecommerce", "EcommerceGlobalModify");
            }
            else
            {
                RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifySuppliers");
            }
        }

        string errorMessage = new Validator().NotEmpty(txtSupplierDisplayName.Text.Trim(), GetString("supplier_Edit.errorEmptyDisplayName")).Result;

        // Validate email format if not empty
        if (errorMessage == "")
        {
            if ((txtSupplierEmail.Text.Trim() != "") && (!ValidationHelper.IsEmail(txtSupplierEmail.Text.Trim())))
            {
                errorMessage = GetString("supplier_Edit.errorEmailFormat");
            }
        }

        if (errorMessage == "")
        {
            SupplierInfo supplierObj = SupplierInfoProvider.GetSupplierInfo(mSupplierId);

            if (supplierObj == null)
            {
                supplierObj = new SupplierInfo();
                // Assign site ID
                supplierObj.SupplierSiteID = ConfiguredSiteID;
            }

            supplierObj.SupplierFax         = txtSupplierFax.Text.Trim();
            supplierObj.SupplierEmail       = txtSupplierEmail.Text.Trim();
            supplierObj.SupplierPhone       = txtSupplierPhone.Text.Trim();
            supplierObj.SupplierDisplayName = txtSupplierDisplayName.Text.Trim();
            supplierObj.SupplierEnabled     = chkSupplierEnabled.Checked;

            // Save changes
            SupplierInfoProvider.SetSupplierInfo(supplierObj);

            URLHelper.Redirect("Supplier_Edit.aspx?supplierid=" + Convert.ToString(supplierObj.SupplierID) + "&saved=1&siteId=" + SiteID);
        }
        else
        {
            lblError.Visible = true;
            lblError.Text    = errorMessage;
        }
    }
Beispiel #3
0
    /// <summary>
    /// Gets object from the specified column of the supplier with specific ID.
    /// </summary>
    /// <param name="Id">Supplier ID</param>
    /// <param name="column">Column name</param>
    public static object GetSupplier(object Id, string column)
    {
        int id = ValidationHelper.GetInteger(Id, 0);

        if ((id > 0) && !DataHelper.IsEmpty(column))
        {
            // Get supplier
            SupplierInfo si = SupplierInfoProvider.GetSupplierInfo(id);

            return(GetColumnValue(si, column));
        }

        return("");
    }
Beispiel #4
0
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void gridElem_OnAction(string actionName, object actionArgument)
    {
        int supplierId = ValidationHelper.GetInteger(actionArgument, 0);

        if (actionName == "edit")
        {
            var url = UIContextHelper.GetElementUrl(ModuleName.ECOMMERCE, "edit.supplier", false, supplierId);
            url = URLHelper.AddParameterToUrl(url, "action", "edit");
            URLHelper.Redirect(url);
        }
        else if (actionName == "delete")
        {
            var supplierObj = SupplierInfoProvider.GetSupplierInfo(supplierId);

            if (supplierObj == null)
            {
                return;
            }

            // Check module permissions
            if (!ECommerceContext.IsUserAuthorizedToModifySupplier(supplierObj))
            {
                if (supplierObj.IsGlobal)
                {
                    RedirectToAccessDenied(ModuleName.ECOMMERCE, EcommercePermissions.ECOMMERCE_MODIFYGLOBAL);
                }
                else
                {
                    RedirectToAccessDenied(ModuleName.ECOMMERCE, "EcommerceModify OR ModifySuppliers");
                }
            }

            if (supplierObj.Generalized.CheckDependencies())
            {
                // Show error message
                ShowError(ECommerceHelper.GetDependencyMessage(supplierObj));

                return;
            }

            // Delete SupplierInfo object from database
            SupplierInfoProvider.DeleteSupplierInfo(supplierObj);
        }
    }
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void gridElem_OnAction(string actionName, object actionArgument)
    {
        int supplierId = ValidationHelper.GetInteger(actionArgument, 0);

        if (actionName == "edit")
        {
            URLHelper.Redirect(UIContextHelper.GetElementUrl("cms.ecommerce", "edit.supplier", false, supplierId));
        }
        else if (actionName == "delete")
        {
            var supplierObj = SupplierInfoProvider.GetSupplierInfo(supplierId);

            if (supplierObj == null)
            {
                return;
            }

            // Check module permissions
            if (!ECommerceContext.IsUserAuthorizedToModifySupplier(supplierObj))
            {
                if (supplierObj.IsGlobal)
                {
                    RedirectToAccessDenied("CMS.Ecommerce", "EcommerceGlobalModify");
                }
                else
                {
                    RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifySuppliers");
                }
            }

            if (supplierObj.Generalized.CheckDependencies())
            {
                // Show error message
                ShowError(GetString("Ecommerce.DeleteDisabled"));

                return;
            }

            // Delete SupplierInfo object from database
            SupplierInfoProvider.DeleteSupplierInfo(supplierObj);
        }
    }
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void gridElem_OnAction(string actionName, object actionArgument)
    {
        if (actionName == "edit")
        {
            URLHelper.Redirect("Supplier_Edit.aspx?supplierid=" + Convert.ToString(actionArgument) + "&siteId=" + SelectSite.SiteID);
        }
        else if (actionName == "delete")
        {
            int          supplierId  = ValidationHelper.GetInteger(actionArgument, 0);
            SupplierInfo supplierObj = SupplierInfoProvider.GetSupplierInfo(supplierId);

            // Check module permissions
            if (!ECommerceContext.IsUserAuthorizedToModifySupplier(supplierObj))
            {
                if (supplierObj.IsGlobal)
                {
                    RedirectToAccessDenied("CMS.Ecommerce", "EcommerceGlobalModify");
                }
                else
                {
                    RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifySuppliers");
                }
            }

            if (SupplierInfoProvider.CheckDependencies(supplierId))
            {
                // Show error message
                ShowError(GetString("Ecommerce.DeleteDisabled"));

                return;
            }

            // Delete SupplierInfo object from database
            SupplierInfoProvider.DeleteSupplierInfo(supplierObj);
            InitWhereCondition();
        }
    }
    /// <summary>
    /// Returns where condition based on webpart fields.
    /// </summary>
    private string GetWhereCondition()
    {
        string where = null;

        // Show products only from current site or global too, based on setting
        if (ECommerceSettings.AllowGlobalProducts(CMSContext.CurrentSiteName))
        {
            where = "(SKUSiteID = " + CMSContext.CurrentSiteID + ") OR (SKUSiteID IS NULL)";
        }
        else
        {
            where = "SKUSiteID = " + CMSContext.CurrentSiteID;
        }

        // Product type filter
        if (!string.IsNullOrEmpty(ProductType) && (ProductType != FILTER_ALL))
        {
            if (ProductType == PRODUCT_TYPE_PRODUCTS)
            {
                where = SqlHelperClass.AddWhereCondition(where, "SKUOptionCategoryID IS NULL");
            }
            else if (ProductType == PRODUCT_TYPE_PRODUCT_OPTIONS)
            {
                where = SqlHelperClass.AddWhereCondition(where, "SKUOptionCategoryID IS NOT NULL");
            }
        }

        // Representing filter
        if (!string.IsNullOrEmpty(Representing) && (Representing != FILTER_ALL))
        {
            SKUProductTypeEnum productTypeEnum   = SKUInfoProvider.GetSKUProductTypeEnum(Representing);
            string             productTypeString = SKUInfoProvider.GetSKUProductTypeString(productTypeEnum);

            where = SqlHelperClass.AddWhereCondition(where, "SKUProductType = N'" + productTypeString + "'");
        }

        // Product number filter
        if (!string.IsNullOrEmpty(ProductNumber))
        {
            string safeProductNumber = SqlHelperClass.GetSafeQueryString(ProductNumber, true);
            where = SqlHelperClass.AddWhereCondition(where, "SKUNumber LIKE N'%" + safeProductNumber + "%'");
        }

        // Department filter
        DepartmentInfo di = DepartmentInfoProvider.GetDepartmentInfo(Department, CurrentSiteName);

        if (di != null)
        {
            where = SqlHelperClass.AddWhereCondition(where, "SKUDepartmentID = " + di.DepartmentID);
        }

        // Manufacturer filter
        ManufacturerInfo mi = ManufacturerInfoProvider.GetManufacturerInfo(Manufacturer, CurrentSiteName);

        if (mi != null)
        {
            where = SqlHelperClass.AddWhereCondition(where, "SKUManufacturerID = " + mi.ManufacturerID);
        }

        // Supplier filter
        SupplierInfo si = SupplierInfoProvider.GetSupplierInfo(Supplier, CurrentSiteName);

        if (si != null)
        {
            where = SqlHelperClass.AddWhereCondition(where, "SKUSupplierID = " + si.SupplierID);
        }

        // Needs shipping filter
        if (!string.IsNullOrEmpty(NeedsShipping) && (NeedsShipping != FILTER_ALL))
        {
            if (NeedsShipping == NEEDS_SHIPPING_YES)
            {
                where = SqlHelperClass.AddWhereCondition(where, "SKUNeedsShipping = 1");
            }
            else if (NeedsShipping == NEEDS_SHIPPING_NO)
            {
                where = SqlHelperClass.AddWhereCondition(where, "(SKUNeedsShipping = 0) OR (SKUNeedsShipping IS NULL)");
            }
        }

        // Price from filter
        if (PriceFrom > 0)
        {
            where = SqlHelperClass.AddWhereCondition(where, "SKUPrice >= " + PriceFrom);
        }

        // Price to filter
        if (PriceTo > 0)
        {
            where = SqlHelperClass.AddWhereCondition(where, "SKUPrice <= " + PriceTo);
        }

        // Public status filter
        PublicStatusInfo psi = PublicStatusInfoProvider.GetPublicStatusInfo(PublicStatus, CurrentSiteName);

        if (psi != null)
        {
            where = SqlHelperClass.AddWhereCondition(where, "SKUPublicStatusID = " + psi.PublicStatusID);
        }

        // Internal status filter
        InternalStatusInfo isi = InternalStatusInfoProvider.GetInternalStatusInfo(InternalStatus, CurrentSiteName);

        if (isi != null)
        {
            where = SqlHelperClass.AddWhereCondition(where, "SKUInternalStatusID = " + isi.InternalStatusID);
        }

        // Allow for sale filter
        if (!string.IsNullOrEmpty(AllowForSale) && (AllowForSale != FILTER_ALL))
        {
            if (AllowForSale == ALLOW_FOR_SALE_YES)
            {
                where = SqlHelperClass.AddWhereCondition(where, "SKUEnabled = 1");
            }
            else if (AllowForSale == ALLOW_FOR_SALE_NO)
            {
                where = SqlHelperClass.AddWhereCondition(where, "(SKUEnabled = 0) OR (SKUEnabled IS NULL)");
            }
        }

        // Available items filter
        if (!string.IsNullOrEmpty(AvailableItems))
        {
            int value = ValidationHelper.GetInteger(AvailableItems, int.MaxValue);
            where = SqlHelperClass.AddWhereCondition(where, "SKUAvailableItems <= " + value);
        }

        // Needs to be reordered filter
        if (NeedsToBeReordered)
        {
            where = SqlHelperClass.AddWhereCondition(where, "((SKUReorderAt IS NULL) AND (SKUAvailableItems <= 0)) OR ((SKUReorderAt IS NOT NULL) AND (SKUAvailableItems <= SKUReorderAt))");
        }

        return(where);
    }
    private object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        DataRowView row = parameter as DataRowView;

        switch (sourceName.ToLowerCSafe())
        {
        case "optioncategory":
            int optionCategoryId = ValidationHelper.GetInteger(row["SKUOptionCategoryID"], 0);
            OptionCategoryInfo optionCategory = OptionCategoryInfoProvider.GetOptionCategoryInfo(optionCategoryId);

            // Return option category display name for product option or '-' for product
            if (optionCategory != null)
            {
                return(HTMLHelper.HTMLEncode(optionCategory.CategoryDisplayName ?? ""));
            }
            return("-");

        case "skunumber":
            string skuNumber = ValidationHelper.GetString(row["SKUNumber"], null);
            return(HTMLHelper.HTMLEncode(skuNumber ?? ""));

        case "skuprice":
            double value  = ValidationHelper.GetDouble(row["SKUPrice"], 0);
            int    siteId = ValidationHelper.GetInteger(row["SKUSiteID"], 0);

            // Format price
            return(CurrencyInfoProvider.GetFormattedPrice(value, siteId));

        case "skudepartmentid":
            // Tranform to display name and localize
            int            departmentId = ValidationHelper.GetInteger(row["SKUDepartmentID"], 0);
            DepartmentInfo department   = DepartmentInfoProvider.GetDepartmentInfo(departmentId);

            return((department != null) ? HTMLHelper.HTMLEncode(ResHelper.LocalizeString(department.DepartmentDisplayName)) : "");

        case "skumanufacturerid":
            // Tranform to display name and localize
            int manufacturerId            = ValidationHelper.GetInteger(row["SKUManufacturerID"], 0);
            ManufacturerInfo manufacturer = ManufacturerInfoProvider.GetManufacturerInfo(manufacturerId);

            return((manufacturer != null) ? HTMLHelper.HTMLEncode(ResHelper.LocalizeString(manufacturer.ManufacturerDisplayName)) : "");

        case "skusupplierid":
            // Tranform to display name and localize
            int          supplierId = ValidationHelper.GetInteger(row["SKUSupplierID"], 0);
            SupplierInfo supplier   = SupplierInfoProvider.GetSupplierInfo(supplierId);

            return((supplier != null) ? HTMLHelper.HTMLEncode(ResHelper.LocalizeString(supplier.SupplierDisplayName)) : "");

        case "skuavailableitems":
            int?count     = row["SKUAvailableItems"] as int?;
            int?reorderAt = row["SKUReorderAt"] as int?;

            // Emphasise the number when product needs to be reordered
            if (count.HasValue && ((reorderAt.HasValue && (count <= reorderAt)) || (!reorderAt.HasValue && (count <= 0))))
            {
                // Format message informing about insufficient stock level
                string reorderMsg = string.Format(GetString("com.sku.reorderatTooltip"), reorderAt);
                return(string.Format("<span class=\"OperationFailed\">{0}</span>", count));
            }
            return(count);

        case "itemstobereordered":
            int skuReorderAt      = ValidationHelper.GetInteger(row["SKUReorderAt"], 0);
            int skuAvailableItems = ValidationHelper.GetInteger(row["SKUAvailableItems"], 0);
            int difference        = skuReorderAt - skuAvailableItems;

            // Return difference, or '-'
            return((difference > 0) ? difference.ToString() : "-");

        case "skusiteid":
            return(UniGridFunctions.ColoredSpanYesNo(row["SKUSiteID"] == DBNull.Value));
        }

        return(parameter);
    }
    /// <summary>
    /// Sets the data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Check module permissions
        bool global = (editedSiteId <= 0);

        if (!ECommerceContext.IsUserAuthorizedToModifySupplier(global))
        {
            if (global)
            {
                RedirectToAccessDenied("CMS.Ecommerce", "EcommerceGlobalModify");
            }
            else
            {
                RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifySuppliers");
            }
        }

        string errorMessage = new Validator().
                              NotEmpty(txtSupplierDisplayName.Text.Trim(), GetString("supplier_Edit.errorEmptyDisplayName")).
                              IsCodeName(txtSupplierName.Text.Trim(), GetString("general.invalidcodename")).Result;

        // Validate email format if not empty
        if (errorMessage == "")
        {
            if ((txtSupplierEmail.Text.Trim() != "") && (!ValidationHelper.IsEmail(txtSupplierEmail.Text.Trim())))
            {
                errorMessage = GetString("supplier_Edit.errorEmailFormat");
            }
        }

        if (errorMessage == "")
        {
            SupplierInfo supplierObj = null;

            // Supplier code name must be unique
            string  siteWhere = (ConfiguredSiteID > 0) ? " AND (SupplierSiteID = " + ConfiguredSiteID + " OR SupplierSiteID IS NULL)" : "";
            DataSet ds        = SupplierInfoProvider.GetSuppliers("SupplierName = N'" + SqlHelperClass.GetSafeQueryString(txtSupplierName.Text.Trim(), false) + "'" + siteWhere, null, 1, null);
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                supplierObj = new SupplierInfo(ds.Tables[0].Rows[0]);
            }

            if ((supplierObj == null) || (supplierObj.SupplierID == mSupplierId))
            {
                if (supplierObj == null)
                {
                    supplierObj = SupplierInfoProvider.GetSupplierInfo(mSupplierId);
                    if (supplierObj == null)
                    {
                        // Create new supplier
                        supplierObj = new SupplierInfo();
                        supplierObj.SupplierSiteID = ConfiguredSiteID;
                    }
                }

                supplierObj.SupplierFax         = txtSupplierFax.Text.Trim();
                supplierObj.SupplierEmail       = txtSupplierEmail.Text.Trim();
                supplierObj.SupplierPhone       = txtSupplierPhone.Text.Trim();
                supplierObj.SupplierDisplayName = txtSupplierDisplayName.Text.Trim();
                supplierObj.SupplierName        = txtSupplierName.Text.Trim();
                supplierObj.SupplierEnabled     = chkSupplierEnabled.Checked;

                // Save changes
                SupplierInfoProvider.SetSupplierInfo(supplierObj);

                URLHelper.Redirect("Supplier_Edit.aspx?supplierid=" + Convert.ToString(supplierObj.SupplierID) + "&saved=1&siteId=" + SiteID);
            }
            else
            {
                // Show error message
                ShowError(GetString("com.suppliernameexists"));
            }
        }
        else
        {
            // Show error message
            ShowError(errorMessage);
        }
    }
Beispiel #10
0
    /// <summary>
    /// Returns where condition based on webpart fields.
    /// </summary>
    private WhereCondition GetWhereCondition()
    {
        var where = new WhereCondition().WhereEquals("SKUSiteID", SiteContext.CurrentSiteID);

        // Show products only from current site or global too, based on setting
        if (ECommerceSettings.AllowGlobalProducts(SiteContext.CurrentSiteName))
        {
            where.Where(w => w.WhereEquals("SKUSiteID", SiteContext.CurrentSiteID).Or().WhereNull("SKUSiteID"));
        }

        // Show/hide product variants - it is based on type of inventory tracking for parent product
        string trackByVariants = TrackInventoryTypeEnum.ByVariants.ToStringRepresentation();

        where.Where(v => v.Where(w => w.WhereNull("SKUParentSKUID").And().WhereNotEquals("SKUTrackInventory", trackByVariants))
                    .Or()
                    .Where(GetParentProductWhereCondition(new WhereCondition().WhereEquals("SKUTrackInventory", trackByVariants))));

        // Product type filter
        if (!string.IsNullOrEmpty(ProductType) && (ProductType != FILTER_ALL))
        {
            if (ProductType == PRODUCT_TYPE_PRODUCTS)
            {
                where.WhereNull("SKUOptionCategoryID");
            }
            else if (ProductType == PRODUCT_TYPE_PRODUCT_OPTIONS)
            {
                where.WhereNotNull("SKUOptionCategoryID");
            }
        }

        // Representing filter
        if (!string.IsNullOrEmpty(Representing) && (Representing != FILTER_ALL))
        {
            SKUProductTypeEnum productTypeEnum   = Representing.ToEnum <SKUProductTypeEnum>();
            string             productTypeString = productTypeEnum.ToStringRepresentation();

            where.WhereEquals("SKUProductType", productTypeString);
        }

        // Product number filter
        if (!string.IsNullOrEmpty(ProductNumber))
        {
            where.WhereContains("SKUNumber", ProductNumber);
        }

        // Department filter
        DepartmentInfo di = DepartmentInfoProvider.GetDepartmentInfo(Department, CurrentSiteName);

        di = di ?? DepartmentInfoProvider.GetDepartmentInfo(Department, null);

        if (di != null)
        {
            where.Where(GetColumnWhereCondition("SKUDepartmentID", new WhereCondition().WhereEquals("SKUDepartmentID", di.DepartmentID)));
        }

        // Manufacturer filter
        ManufacturerInfo mi = ManufacturerInfoProvider.GetManufacturerInfo(Manufacturer, CurrentSiteName);

        mi = mi ?? ManufacturerInfoProvider.GetManufacturerInfo(Manufacturer, null);
        if (mi != null)
        {
            where.Where(GetColumnWhereCondition("SKUManufacturerID", new WhereCondition().WhereEquals("SKUManufacturerID", mi.ManufacturerID)));
        }

        // Supplier filter
        SupplierInfo si = SupplierInfoProvider.GetSupplierInfo(Supplier, CurrentSiteName);

        si = si ?? SupplierInfoProvider.GetSupplierInfo(Supplier, null);
        if (si != null)
        {
            where.Where(GetColumnWhereCondition("SKUSupplierID", new WhereCondition().WhereEquals("SKUSupplierID", si.SupplierID)));
        }

        // Needs shipping filter
        if (!string.IsNullOrEmpty(NeedsShipping) && (NeedsShipping != FILTER_ALL))
        {
            if (NeedsShipping == NEEDS_SHIPPING_YES)
            {
                where.Where(GetColumnWhereCondition("SKUNeedsShipping", new WhereCondition().WhereTrue("SKUNeedsShipping")));
            }
            else if (NeedsShipping == NEEDS_SHIPPING_NO)
            {
                where.Where(GetColumnWhereCondition("SKUNeedsShipping", new WhereCondition().WhereFalse("SKUNeedsShipping").Or().WhereNull("SKUNeedsShipping")));
            }
        }

        // Price from filter
        if (PriceFrom > 0)
        {
            where.WhereGreaterOrEquals("SKUPrice", PriceFrom);
        }

        // Price to filter
        if (PriceTo > 0)
        {
            where.WhereLessOrEquals("SKUPrice", PriceTo);
        }

        // Public status filter
        PublicStatusInfo psi = PublicStatusInfoProvider.GetPublicStatusInfo(PublicStatus, CurrentSiteName);

        if (psi != null)
        {
            where.Where(GetColumnWhereCondition("SKUPublicStatusID", new WhereCondition().WhereEquals("SKUPublicStatusID", psi.PublicStatusID)));
        }

        // Internal status filter
        InternalStatusInfo isi = InternalStatusInfoProvider.GetInternalStatusInfo(InternalStatus, CurrentSiteName);

        if (isi != null)
        {
            where.Where(GetColumnWhereCondition("SKUInternalStatusID", new WhereCondition().WhereEquals("SKUInternalStatusID", isi.InternalStatusID)));
        }

        // Allow for sale filter
        if (!string.IsNullOrEmpty(AllowForSale) && (AllowForSale != FILTER_ALL))
        {
            if (AllowForSale == ALLOW_FOR_SALE_YES)
            {
                where.WhereTrue("SKUEnabled");
            }
            else if (AllowForSale == ALLOW_FOR_SALE_NO)
            {
                where.WhereEqualsOrNull("SKUEnabled", false);
            }
        }

        // Available items filter
        if (!string.IsNullOrEmpty(AvailableItems))
        {
            int value = ValidationHelper.GetInteger(AvailableItems, int.MaxValue);
            where.WhereLessOrEquals("SKUAvailableItems", value);
        }

        // Needs to be reordered filter
        if (NeedsToBeReordered)
        {
            where.Where(w => w.Where(v => v.WhereNull("SKUReorderAt").And().WhereLessOrEquals("SKUAvailableItems", 0))
                        .Or()
                        .Where(z => z.WhereNotNull("SKUReorderAt").And().WhereLessOrEquals("SKUAvailableItems".AsColumn(), "SKUReorderAt".AsColumn())));
        }

        return(where);
    }
Beispiel #11
0
    private object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        DataRowView rowView = parameter as DataRowView;

        if (rowView != null)
        {
            SKUInfo sku = new SKUInfo(rowView.Row);
            switch (sourceName.ToLowerCSafe())
            {
            case "skuname":
                string fullName = sku.SKUName;

                // For variant, add name from parent SKU
                if (sku.SKUParentSKUID != 0)
                {
                    SKUInfo parentSku = SKUInfoProvider.GetSKUInfo(sku.SKUParentSKUID);
                    fullName = string.Format("{0}: {1}", parentSku.SKUName, sku.SKUName);
                }
                return(HTMLHelper.HTMLEncode(fullName));

            case "optioncategory":
                OptionCategoryInfo optionCategory = OptionCategoryInfoProvider.GetOptionCategoryInfo(sku.SKUOptionCategoryID);

                // Return option category display name for product option or '-' for product
                if (optionCategory != null)
                {
                    return(HTMLHelper.HTMLEncode(optionCategory.CategoryDisplayName ?? ""));
                }
                return("-");

            case "skunumber":
                return(ResHelper.LocalizeString(sku.SKUNumber, null, true));

            case "skuprice":
                // Format price
                return(CurrencyInfoProvider.GetFormattedPrice(sku.SKUPrice, sku.SKUSiteID));

            case "skudepartmentid":
                // Transform to display name and localize
                DepartmentInfo department = DepartmentInfoProvider.GetDepartmentInfo(sku.SKUDepartmentID);
                return((department != null) ? HTMLHelper.HTMLEncode(ResHelper.LocalizeString(department.DepartmentDisplayName)) : "");

            case "skumanufacturerid":
                // Transform to display name and localize
                ManufacturerInfo manufacturer = ManufacturerInfoProvider.GetManufacturerInfo(sku.SKUManufacturerID);
                return((manufacturer != null) ? HTMLHelper.HTMLEncode(ResHelper.LocalizeString(manufacturer.ManufacturerDisplayName)) : "");

            case "skusupplierid":
                // Transform to display name and localize
                SupplierInfo supplier = SupplierInfoProvider.GetSupplierInfo(sku.SKUSupplierID);
                return((supplier != null) ? HTMLHelper.HTMLEncode(ResHelper.LocalizeString(supplier.SupplierDisplayName)) : "");

            case "skupublicstatusid":
                // Transform to display name and localize
                PublicStatusInfo publicStatus = PublicStatusInfoProvider.GetPublicStatusInfo(sku.SKUPublicStatusID);
                return((publicStatus != null) ? HTMLHelper.HTMLEncode(ResHelper.LocalizeString(publicStatus.PublicStatusDisplayName)) : "");

            case "skuinternalstatusid":
                // Transform to display name and localize
                InternalStatusInfo internalStatus = InternalStatusInfoProvider.GetInternalStatusInfo(sku.SKUInternalStatusID);
                return((internalStatus != null) ? HTMLHelper.HTMLEncode(ResHelper.LocalizeString(internalStatus.InternalStatusDisplayName)) : "");

            case "skuavailableitems":
                int?count     = sku.SKUAvailableItems as int?;
                int?reorderAt = sku.SKUReorderAt as int?;

                // Emphasize the number when product needs to be reordered
                if (count.HasValue && ((reorderAt.HasValue && (count <= reorderAt)) || (!reorderAt.HasValue && (count <= 0))))
                {
                    // Format message informing about insufficient stock level
                    return(string.Format("<span class=\"OperationFailed\">{0}</span>", count));
                }
                return(count);

            case "itemstobereordered":
                int difference = sku.SKUReorderAt - sku.SKUAvailableItems;

                // Return difference, or '-'
                return((difference > 0) ? difference.ToString() : "-");

            case "skusiteid":
                return(UniGridFunctions.ColoredSpanYesNo(sku.SKUSiteID == 0));
            }
        }

        return(parameter);
    }
    /// <summary>
    /// Returns where condition based on webpart fields.
    /// </summary>
    private string GetWhereCondition()
    {
        string where = "SKUSiteID = " + SiteContext.CurrentSiteID;

        // Show products only from current site or global too, based on setting
        if (ECommerceSettings.AllowGlobalProducts(SiteContext.CurrentSiteName))
        {
            where = "(SKUSiteID = " + SiteContext.CurrentSiteID + ") OR (SKUSiteID IS NULL)";
        }

        // Show/hide product variants - it is based on type of inventory tracking for parent product
        string trackByVariants = TrackInventoryTypeEnum.ByVariants.ToStringRepresentation();
        string parentSkuWhere  = "(SKUParentSKUID IS NULL) AND (SKUTrackInventory != '" + trackByVariants + "')";
        string variantWhere    = GetParentProductWhereCondition("SKUTrackInventory = '" + trackByVariants + "'");

        where = SqlHelper.AddWhereCondition(where, string.Format("({0}) OR ({1})", parentSkuWhere, variantWhere));

        // Product type filter
        if (!string.IsNullOrEmpty(ProductType) && (ProductType != FILTER_ALL))
        {
            if (ProductType == PRODUCT_TYPE_PRODUCTS)
            {
                where = SqlHelper.AddWhereCondition(where, "SKUOptionCategoryID IS NULL");
            }
            else if (ProductType == PRODUCT_TYPE_PRODUCT_OPTIONS)
            {
                where = SqlHelper.AddWhereCondition(where, "SKUOptionCategoryID IS NOT NULL");
            }
        }

        // Representing filter
        if (!string.IsNullOrEmpty(Representing) && (Representing != FILTER_ALL))
        {
            SKUProductTypeEnum productTypeEnum   = Representing.ToEnum <SKUProductTypeEnum>();
            string             productTypeString = productTypeEnum.ToStringRepresentation();

            where = SqlHelper.AddWhereCondition(where, "SKUProductType = N'" + productTypeString + "'");
        }

        // Product number filter
        if (!string.IsNullOrEmpty(ProductNumber))
        {
            string safeProductNumber = SqlHelper.GetSafeQueryString(ProductNumber, true);
            where = SqlHelper.AddWhereCondition(where, "SKUNumber LIKE N'%" + safeProductNumber + "%'");
        }

        // Department filter
        DepartmentInfo di = DepartmentInfoProvider.GetDepartmentInfo(Department, CurrentSiteName);

        di = di ?? DepartmentInfoProvider.GetDepartmentInfo(Department, null);

        if (di != null)
        {
            where = SqlHelper.AddWhereCondition(where, GetColumnWhereCondition("SKUDepartmentID", "SKUDepartmentID = " + di.DepartmentID));
        }

        // Manufacturer filter
        ManufacturerInfo mi = ManufacturerInfoProvider.GetManufacturerInfo(Manufacturer, CurrentSiteName);

        mi = mi ?? ManufacturerInfoProvider.GetManufacturerInfo(Manufacturer, null);
        if (mi != null)
        {
            where = SqlHelper.AddWhereCondition(where, GetColumnWhereCondition("SKUManufacturerID", "SKUManufacturerID = " + mi.ManufacturerID));
        }

        // Supplier filter
        SupplierInfo si = SupplierInfoProvider.GetSupplierInfo(Supplier, CurrentSiteName);

        si = si ?? SupplierInfoProvider.GetSupplierInfo(Supplier, null);
        if (si != null)
        {
            where = SqlHelper.AddWhereCondition(where, GetColumnWhereCondition("SKUSupplierID", "SKUSupplierID = " + si.SupplierID));
        }

        // Needs shipping filter
        if (!string.IsNullOrEmpty(NeedsShipping) && (NeedsShipping != FILTER_ALL))
        {
            if (NeedsShipping == NEEDS_SHIPPING_YES)
            {
                where = SqlHelper.AddWhereCondition(where, GetColumnWhereCondition("SKUNeedsShipping", "SKUNeedsShipping = 1"));
            }
            else if (NeedsShipping == NEEDS_SHIPPING_NO)
            {
                where = SqlHelper.AddWhereCondition(where, GetColumnWhereCondition("SKUNeedsShipping", "(SKUNeedsShipping = 0) OR (SKUNeedsShipping IS NULL)"));
            }
        }

        // Price from filter
        if (PriceFrom > 0)
        {
            where = SqlHelper.AddWhereCondition(where, "SKUPrice >= " + PriceFrom);
        }

        // Price to filter
        if (PriceTo > 0)
        {
            where = SqlHelper.AddWhereCondition(where, "SKUPrice <= " + PriceTo);
        }

        // Public status filter
        PublicStatusInfo psi = PublicStatusInfoProvider.GetPublicStatusInfo(PublicStatus, CurrentSiteName);

        if (psi != null)
        {
            where = SqlHelper.AddWhereCondition(where, GetColumnWhereCondition("SKUPublicStatusID", "SKUPublicStatusID = " + psi.PublicStatusID));
        }

        // Internal status filter
        InternalStatusInfo isi = InternalStatusInfoProvider.GetInternalStatusInfo(InternalStatus, CurrentSiteName);

        if (isi != null)
        {
            where = SqlHelper.AddWhereCondition(where, GetColumnWhereCondition("SKUInternalStatusID", "SKUInternalStatusID = " + isi.InternalStatusID));
        }

        // Allow for sale filter
        if (!string.IsNullOrEmpty(AllowForSale) && (AllowForSale != FILTER_ALL))
        {
            if (AllowForSale == ALLOW_FOR_SALE_YES)
            {
                where = SqlHelper.AddWhereCondition(where, "SKUEnabled = 1");
            }
            else if (AllowForSale == ALLOW_FOR_SALE_NO)
            {
                where = SqlHelper.AddWhereCondition(where, "(SKUEnabled = 0) OR (SKUEnabled IS NULL)");
            }
        }

        // Available items filter
        if (!string.IsNullOrEmpty(AvailableItems))
        {
            int value = ValidationHelper.GetInteger(AvailableItems, int.MaxValue);
            where = SqlHelper.AddWhereCondition(where, "SKUAvailableItems <= " + value);
        }

        // Needs to be reordered filter
        if (NeedsToBeReordered)
        {
            where = SqlHelper.AddWhereCondition(where, "((SKUReorderAt IS NULL) AND (SKUAvailableItems <= 0)) OR ((SKUReorderAt IS NOT NULL) AND (SKUAvailableItems <= SKUReorderAt))");
        }

        return(where);
    }
    /// <summary>
    /// Convert given supplier name to its ID for specified site.
    /// </summary>
    /// <param name="name">Code name of the supplier.</param>
    /// <param name="siteName">Name of the site to translate code name for.</param>
    protected override int GetID(string name, string siteName)
    {
        var supplierInfoObj = SupplierInfoProvider.GetSupplierInfo(name, siteName);

        return((supplierInfoObj != null) ? supplierInfoObj.SupplierID : 0);
    }
Beispiel #14
0
    protected void Page_Load(object sender, EventArgs e)
    {
        rfvDisplayName.ErrorMessage = GetString("supplier_Edit.errorEmptyDisplayName");

        // control initializations
        lblSupplierFax.Text         = GetString("supplier_Edit.SupplierFaxLabel");
        lblSupplierEmail.Text       = GetString("supplier_Edit.SupplierEmailLabel");
        lblSupplierPhone.Text       = GetString("supplier_Edit.SupplierPhoneLabel");
        lblSupplierDisplayName.Text = GetString("supplier_Edit.SupplierDisplayNameLabel");

        btnOk.Text = GetString("General.OK");

        string currentSupplier = GetString("supplier_Edit.NewItemCaption");

        // Get supplier ID from querystring
        mSupplierId  = QueryHelper.GetInteger("supplierid", 0);
        editedSiteId = ConfiguredSiteID;

        if (mSupplierId > 0)
        {
            SupplierInfo supplierObj = SupplierInfoProvider.GetSupplierInfo(mSupplierId);
            EditedObject = supplierObj;

            if (supplierObj != null)
            {
                currentSupplier = supplierObj.SupplierDisplayName;
                // Store site id of edited supplier
                editedSiteId = supplierObj.SupplierSiteID;

                //Check site id of edited supplier
                CheckEditedObjectSiteID(editedSiteId);

                // Fill editing form
                if (!RequestHelper.IsPostBack())
                {
                    LoadData(supplierObj);

                    // Show that the supplier was created or updated successfully
                    if (QueryHelper.GetBoolean("saved", false))
                    {
                        lblInfo.Visible = true;
                        lblInfo.Text    = GetString("General.ChangesSaved");
                    }
                }
            }
        }

        this.CurrentMaster.Title.HelpTopicName = "newedit_supplier";
        this.CurrentMaster.Title.HelpName      = "helpTopic";

        // Initializes page title breadcrumbs control
        string[,] breadcrumbs = new string[2, 3];
        breadcrumbs[0, 0]     = GetString("supplier_Edit.ItemListLink");
        breadcrumbs[0, 1]     = "~/CMSModules/Ecommerce/Pages/Tools/Suppliers/Supplier_List.aspx?siteId=" + this.SiteID;
        breadcrumbs[0, 2]     = "";
        breadcrumbs[1, 0]     = FormatBreadcrumbObjectName(currentSupplier, editedSiteId);
        breadcrumbs[1, 1]     = "";
        breadcrumbs[1, 2]     = "";
        this.CurrentMaster.Title.Breadcrumbs = breadcrumbs;

        // Set master title
        if (mSupplierId > 0)
        {
            this.CurrentMaster.Title.TitleText  = GetString("com.supplier.edit");
            this.CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Ecommerce_Supplier/object.png");
        }
        else
        {
            this.CurrentMaster.Title.TitleText  = GetString("supplier_List.NewItemCaption");
            this.CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Ecommerce_Supplier/new.png");
        }

        AddMenuButtonSelectScript("Suppliers", "");
    }