/// <summary> /// Gets object from the specified column of the manufacturer with specific ID. /// </summary> /// <param name="Id">Manufacturer ID</param> /// <param name="column">Column name</param> public static object GetManufacturer(object Id, string column) { int id = ValidationHelper.GetInteger(Id, 0); if ((id > 0) && !DataHelper.IsEmpty(column)) { // Get manufacturer ManufacturerInfo mi = ManufacturerInfoProvider.GetManufacturerInfo(id); return(GetColumnValue(mi, column)); } return(""); }
/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { // Check module permissions bool global = (editedSiteId <= 0); if (!ECommerceContext.IsUserAuthorizedToModifyManufacturer(global)) { if (global) { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceGlobalModify"); } else { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyManufacturers"); } } // Check input values from textboxes and other controls - new Validator() string errorMessage = new Validator().NotEmpty(txtManufacturerDisplayName.Text.Trim(), GetString("manufacturer_Edit.errorEmptyDisplayName")).Result; if (errorMessage == "") { ManufacturerInfo manufacturerObj = ManufacturerInfoProvider.GetManufacturerInfo(manufacturerId); if (manufacturerObj == null) { manufacturerObj = new ManufacturerInfo(); // Assign site ID manufacturerObj.ManufacturerSiteID = ConfiguredSiteID; } manufacturerObj.ManufacturerID = manufacturerId; manufacturerObj.ManufacturerDisplayName = txtManufacturerDisplayName.Text.Trim(); manufacturerObj.ManufactureHomepage = txtManufactureHomepage.Text.Trim(); manufacturerObj.ManufacturerEnabled = chkManufacturerEnabled.Checked; // Save changes ManufacturerInfoProvider.SetManufacturerInfo(manufacturerObj); URLHelper.Redirect("Manufacturer_Edit.aspx?manufacturerId=" + Convert.ToString(manufacturerObj.ManufacturerID) + "&saved=1&siteId=" + SiteID.ToString()); } else { lblError.Visible = true; lblError.Text = errorMessage; } }
/// <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 uniGrid_OnAction(string actionName, object actionArgument) { int manufacturerId = ValidationHelper.GetInteger(actionArgument, 0); if (actionName == "edit") { URLHelper.Redirect(UIContextHelper.GetElementUrl("CMS.Ecommerce", "EditManufacturer", false, actionArgument.ToInteger(0))); } else if (actionName == "delete") { // Check module permissions var manufacturerObj = ManufacturerInfoProvider.GetManufacturerInfo(manufacturerId); if (manufacturerObj != null) { if (!ECommerceContext.IsUserAuthorizedToModifyManufacturer(manufacturerObj)) { if (manufacturerObj.IsGlobal) { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceGlobalModify"); } else { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyManufacturers"); } } // Check dependencies if (manufacturerObj.Generalized.CheckDependencies()) { // Show error message ShowError(GetString("Ecommerce.DeleteDisabled")); return; } // Delete ManufacturerInfo object from database ManufacturerInfoProvider.DeleteManufacturerInfo(manufacturerObj); } } }
/// <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 uniGrid_OnAction(string actionName, object actionArgument) { int manufacturerId = ValidationHelper.GetInteger(actionArgument, 0); if (actionName == "edit") { URLHelper.Redirect("Manufacturer_Edit.aspx?manufacturerId=" + manufacturerId + "&siteId=" + SelectSite.SiteID); } else if (actionName == "delete") { // Check module permissions ManufacturerInfo manufacturerObj = ManufacturerInfoProvider.GetManufacturerInfo(manufacturerId); if (!ECommerceContext.IsUserAuthorizedToModifyManufacturer(manufacturerObj)) { if (manufacturerObj.IsGlobal) { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceGlobalModify"); } else { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyManufacturers"); } } // Check dependencies if (ManufacturerInfoProvider.CheckDependencies(manufacturerId)) { // Show error message ShowError(GetString("Ecommerce.DeleteDisabled")); return; } // Delete ManufacturerInfo object from database ManufacturerInfoProvider.DeleteManufacturerInfo(manufacturerObj); InitWhereCondition(); } }
/// <summary> /// Gets object from the specified column of the manufacturer with specific ID. /// </summary> /// <param name="Id">Manufacturer ID</param> /// <param name="column">Column name</param> public static object GetManufacturer(object Id, string column) { int id = ValidationHelper.GetInteger(Id, 0); if ((id > 0) && !DataHelper.IsEmpty(column)) { // Get manufacturer ManufacturerInfo mi = ManufacturerInfoProvider.GetManufacturerInfo(id); if (mi != null) { // Return datarow value if specified column exists if (mi.ContainsColumn(column)) { return(mi.GetValue(column)); } else { return(""); } } } return(""); }
/// <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> /// 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); }
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 manufacturer name to its ID for specified site. /// </summary> /// <param name="name">Code name of the manufacturer.</param> /// <param name="siteName">Name of the site to translate code name for.</param> protected override int GetID(string name, string siteName) { ManufacturerInfo manufacturerInfoObj = ManufacturerInfoProvider.GetManufacturerInfo(name, siteName); return((manufacturerInfoObj != null) ? manufacturerInfoObj.ManufacturerID : 0); }
protected void Page_Load(object sender, EventArgs e) { // Field validator error messages initialization rfvDisplayName.ErrorMessage = GetString("manufacturer_Edit.errorEmptyDisplayName"); // Control initializations lblManufacturerDisplayName.Text = GetString("Manufacturer_Edit.ManufacturerDisplayNameLabel"); lblManufactureHomepage.Text = GetString("Manufacturer_Edit.ManufactureHomepageLabel"); btnOk.Text = GetString("General.OK"); string currentManufacturer = GetString("Manufacturer_Edit.NewItemCaption"); // Get manufacturer id from querystring manufacturerId = QueryHelper.GetInteger("manufacturerId", 0); editedSiteId = ConfiguredSiteID; if (manufacturerId > 0) { ManufacturerInfo manufacturerObj = ManufacturerInfoProvider.GetManufacturerInfo(manufacturerId); EditedObject = manufacturerObj; if (manufacturerObj != null) { currentManufacturer = manufacturerObj.ManufacturerDisplayName; editedSiteId = manufacturerObj.ManufacturerSiteID; // Check edited object site ID CheckEditedObjectSiteID(editedSiteId); // Fill editing form if (!RequestHelper.IsPostBack()) { LoadData(manufacturerObj); // Show that the manufacturer was created or updated successfully if (ValidationHelper.GetString(Request.QueryString["saved"], "") == "1") { lblInfo.Visible = true; lblInfo.Text = GetString("General.ChangesSaved"); } } } } this.CurrentMaster.Title.HelpTopicName = "newedit_manufacturer"; this.CurrentMaster.Title.HelpName = "helpTopic"; // Initializes page title control string[,] breadcrumbs = new string[2, 3]; breadcrumbs[0, 0] = GetString("Manufacturer_Edit.ItemListLink"); breadcrumbs[0, 1] = "~/CMSModules/Ecommerce/Pages/Tools/Manufacturers/Manufacturer_List.aspx?siteId=" + this.SiteID; breadcrumbs[0, 2] = ""; breadcrumbs[1, 0] = FormatBreadcrumbObjectName(currentManufacturer, editedSiteId); breadcrumbs[1, 1] = ""; breadcrumbs[1, 2] = ""; this.CurrentMaster.Title.Breadcrumbs = breadcrumbs; // Set master title if (manufacturerId > 0) { this.CurrentMaster.Title.TitleText = GetString("com.manufacturer.edit"); this.CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Ecommerce_Manufacturer/object.png"); } else { this.CurrentMaster.Title.TitleText = GetString("Manufacturer_List.NewItemCaption"); this.CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Ecommerce_Manufacturer/new.png"); } AddMenuButtonSelectScript("Manufacturers", ""); }
private void GenerateEcommerceData(int siteID) { var siteName = SiteInfoProvider.GetSiteName(siteID); var currencyInfo = CurrencyInfoProvider.GetCurrencies(siteID) .Where("CurrencyIsMain", QueryOperator.Equals, 1).TopN(1).FirstOrDefault(); var list1 = PaymentOptionInfoProvider.GetPaymentOptions(siteID).ToList(); var list2 = ShippingOptionInfoProvider.GetShippingOptions(siteID).ToList(); var orderStatusList = OrderStatusInfoProvider.GetOrderStatuses(siteID).ToDictionary(status => status.StatusName); var manufacturerExceptionList = new List <int> { ManufacturerInfoProvider.GetManufacturerInfo("Aerobie", siteName).ManufacturerID, //ManufacturerInfoProvider.GetManufacturerInfo("Chemex", siteName).ManufacturerID, //ManufacturerInfoProvider.GetManufacturerInfo("Espro", siteName).ManufacturerID }; var list3 = SKUInfoProvider.GetSKUs(siteID).ToList().Where(sku => { if (sku.IsProduct) { return(!manufacturerExceptionList.Contains(sku.SKUManufacturerID)); } return(false); }).ToList(); int num1; IList <int> intList; if (CustomerInfoProvider.GetCustomers().WhereEquals("CustomerSiteID", siteID).Count < 50) { num1 = customerNames.Length; intList = new List <int>(); for (var index = 0; index < num1; ++index) { intList.Add(GenerateCustomer(customerNames[index], siteID).CustomerID); } } else { intList = DataHelper.GetIntegerValues(CustomerInfoProvider.GetCustomers().Column("CustomerID") .WhereEquals("CustomerSiteID", siteID).WhereNotEquals("CustomerEmail", "alex").Tables[0], "CustomerID"); num1 = intList.Count; } var num2 = 0; var num3 = 0; for (var index1 = 0; index1 <= 30; ++index1) { ++num2; var num4 = 0; if (index1 > 5) { num4 = rand.Next(-1, 2); } for (var index2 = 0; index2 < num2 / 2 + num4; ++index2) { var orderStatusInfo = index1 >= 25 ? index1 >= 29 ? orderStatusList["New"] : orderStatusList["InProgress"] : orderStatusList["Completed"]; var orderInfo = new OrderInfo { OrderCustomerID = intList[num3 % num1], OrderCurrencyID = currencyInfo.CurrencyID, OrderSiteID = siteID, OrderStatusID = orderStatusInfo.StatusID, OrderIsPaid = "Completed".Equals(orderStatusInfo.StatusName, StringComparison.Ordinal) || (uint)rand.Next(0, 2) > 0U, OrderShippingOptionID = list2[rand.Next(list2.Count)].ShippingOptionID, OrderPaymentOptionID = list1[rand.Next(list1.Count)].PaymentOptionID, OrderGrandTotal = decimal.Zero, OrderGrandTotalInMainCurrency = decimal.Zero, OrderTotalPrice = decimal.Zero, OrderTotalPriceInMainCurrency = decimal.Zero, OrderTotalShipping = new decimal(10), OrderTotalTax = new decimal(10) }; OrderInfoProvider.SetOrderInfo(orderInfo); var orderItems = GenerateOrderItems(orderInfo, list3); GenerateOrderAddress(orderInfo.OrderID, GetRandomCountryId(), AddressType.Billing); GenerateOrderAddress(orderInfo.OrderID, GetRandomCountryId(), AddressType.Shipping); orderInfo.OrderDate = DateTime.Now.AddDays(index1 - 30); orderInfo.OrderTotalPrice = orderItems; orderInfo.OrderTotalPriceInMainCurrency = orderItems; orderInfo.OrderGrandTotal = orderItems; orderInfo.OrderGrandTotalInMainCurrency = orderItems; var cartInfoFromOrder = ShoppingCartInfoProvider.GetShoppingCartInfoFromOrder(orderInfo.OrderID); orderInfo.OrderInvoiceNumber = OrderInfoProvider.GenerateInvoiceNumber(cartInfoFromOrder); orderInfo.OrderInvoice = ShoppingCartInfoProvider.GetOrderInvoice(cartInfoFromOrder); OrderInfoProvider.SetOrderInfo(orderInfo); ++num3; } } if (UserInfoProvider.GetUserInfo("alex") != null) { return; } var customerInfo = new CustomerInfo { CustomerEmail = "*****@*****.**", CustomerFirstName = "Alexander", CustomerLastName = "Adams", CustomerSiteID = siteID, CustomerCompany = "Alex & Co. Ltd", CustomerTaxRegistrationID = "12S379BDF798", CustomerOrganizationID = "WRQ7987VRG79" }; CustomerInfoProvider.SetCustomerInfo(customerInfo); var userInfo = CustomerInfoProvider.RegisterCustomer(customerInfo, "", "alex"); var roleInfo = RoleInfoProvider.GetRoleInfo("SilverPartner", siteID); if (roleInfo != null) { UserInfoProvider.AddUserToRole(userInfo.UserID, roleInfo.RoleID); } for (var index = 0; index < 5; ++index) { var cart = new ShoppingCartInfo(); cart.ShoppingCartCulture = CultureHelper.GetDefaultCultureCode(siteName); cart.ShoppingCartCurrencyID = currencyInfo.CurrencyID; cart.ShoppingCartSiteID = siteID; cart.ShoppingCartCustomerID = customerInfo.CustomerID; cart.ShoppingCartBillingAddress = GenerateAddress(GetRandomCountryId(), customerInfo.CustomerID); cart.ShoppingCartShippingAddress = GenerateAddress(GetRandomCountryId(), customerInfo.CustomerID); cart.User = userInfo; ShoppingCartInfoProvider.SetShoppingCartInfo(cart); ShoppingCartInfoProvider.SetShoppingCartItem(cart, new ShoppingCartItemParameters(list3.ElementAt(rand.Next(list3.Count)).SKUID, rand.Next(5))); cart.Evaluate(); ShoppingCartInfoProvider.SetOrder(cart); } }
/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { // Check module permissions bool global = (editedSiteId <= 0); if (!ECommerceContext.IsUserAuthorizedToModifyManufacturer(global)) { if (global) { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceGlobalModify"); } else { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyManufacturers"); } } // Check input values from textboxes and other controls - new Validator() string errorMessage = new Validator(). NotEmpty(txtManufacturerDisplayName.Text.Trim(), GetString("manufacturer_Edit.errorEmptyDisplayName")). IsCodeName(txtManufacturerName.Text.Trim(), GetString("general.invalidcodename")).Result; if (errorMessage == "") { ManufacturerInfo manufacturerObj = null; // Manufacturer code name must be unique string siteWhere = (ConfiguredSiteID > 0) ? " AND (ManufacturerSiteID = " + ConfiguredSiteID + " OR ManufacturerSiteID IS NULL)" : ""; DataSet ds = ManufacturerInfoProvider.GetManufacturers("ManufacturerName = N'" + SqlHelperClass.GetSafeQueryString(txtManufacturerName.Text.Trim(), false) + "'" + siteWhere, null, 1, null); if (!DataHelper.DataSourceIsEmpty(ds)) { manufacturerObj = new ManufacturerInfo(ds.Tables[0].Rows[0]); } if ((manufacturerObj == null) || (manufacturerObj.ManufacturerID == manufacturerId)) { if (manufacturerObj == null) { manufacturerObj = ManufacturerInfoProvider.GetManufacturerInfo(manufacturerId); if (manufacturerObj == null) { // Create new manufacturer manufacturerObj = new ManufacturerInfo(); manufacturerObj.ManufacturerSiteID = ConfiguredSiteID; } } manufacturerObj.ManufacturerID = manufacturerId; manufacturerObj.ManufacturerDisplayName = txtManufacturerDisplayName.Text.Trim(); manufacturerObj.ManufacturerName = txtManufacturerName.Text.Trim(); manufacturerObj.ManufacturerDescription = txtDescription.Text.Trim(); manufacturerObj.ManufacturerHomepage = txtManufactureHomepage.Text.Trim(); manufacturerObj.ManufacturerEnabled = chkManufacturerEnabled.Checked; manufacturerObj.ManufacturerIsImportant = chkIsImportant.Checked; bool isNew = (manufacturerObj.ManufacturerID <= 0); // Save changes ManufacturerInfoProvider.SetManufacturerInfo(manufacturerObj); if (isNew) { file.ObjectID = manufacturerObj.ManufacturerID; file.UploadFile(); } URLHelper.Redirect("Manufacturer_Edit.aspx?manufacturerId=" + Convert.ToString(manufacturerObj.ManufacturerID) + "&saved=1&siteId=" + SiteID.ToString()); } else { // Show error message ShowError(GetString("com.manufacturernameexists")); } } else { // Show error message ShowError(errorMessage); } }
/// <summary> /// Convert given manufacturer name to its ID for specified site. /// </summary> /// <param name="name">Code name of the manufacturer.</param> /// <param name="siteName">Name of the site to translate code name for.</param> protected override int GetID(string name, string siteName) { ManufacturerInfo manufacturerInfoObj = ManufacturerInfoProvider.GetManufacturerInfo(name, siteName); return(manufacturerInfoObj?.ManufacturerID ?? 0); }