void EditForm_OnItemValidation(object sender, ref string errorMessage) { // Look for record with same minimum weight FormEngineUserControl ctrl = sender as FormEngineUserControl; if ((ctrl != null) && (ctrl.FieldInfo.Name == "ShippingCostMinWeight")) { // Check if entered value is double number if (!ValidationHelper.IsDouble(ctrl.Value)) { EditForm.StopProcessing = false; return; } ShippingCostInfo editedObj = ctrl.Data as ShippingCostInfo; if ((mShippingOptionObj != null) && (editedObj != null)) { double weight = ValidationHelper.GetDouble(ctrl.Value, 0); DataSet ds = ShippingCostInfoProvider.GetShippingCosts() .TopN(1) .Columns("ShippingCostID") .WhereEquals("ShippingCostMinWeight", weight) .WhereEquals("ShippingCostShippingOptionID", mShippingOptionObj.ShippingOptionID) .Where("ShippingCostID", QueryOperator.NotEquals, editedObj.ShippingCostID); if (!DataHelper.DataSourceIsEmpty(ds)) { errorMessage = GetString("com.ui.shippingcost.edit_costexists"); EditForm.StopProcessing = false; } } } }
protected void Page_Load(object sender, EventArgs e) { if (IsMultiStoreConfiguration) { CheckUIElementAccessHierarchical(ModuleName.ECOMMERCE, "Ecommerce.GlobalShippingOptions.ShippingCosts"); } else { CheckUIElementAccessHierarchical(ModuleName.ECOMMERCE, "Configuration.ShippingOptions.ShippingCosts"); } // Register item validation EditForm.OnItemValidation += EditForm_OnItemValidation; mShippingOptionObj = EditedObjectParent as ShippingOptionInfo; if (mShippingOptionObj != null) { // Register check permissions EditForm.OnCheckPermissions += (s, args) => CheckConfigurationModification(mShippingOptionObj.ShippingOptionSiteID); } else { // Invalid shipping option EditedObject = null; return; } ShippingCostInfo shippingCostObj = EditedObject as ShippingCostInfo; if (shippingCostObj != null) { // Check if edited shipping cost is assigned to shipping option if ((shippingCostObj.ShippingCostID != 0) && (shippingCostObj.ShippingCostShippingOptionID != mShippingOptionObj.ShippingOptionID)) { EditedObject = null; } // Check if not editing object from another site CheckEditedObjectSiteID(mShippingOptionObj.ShippingOptionSiteID); // Check presence of main currency CheckMainCurrency(mShippingOptionObj.ShippingOptionSiteID); } }
protected void Page_Load(object sender, EventArgs e) { // Register item validation EditForm.OnItemValidation += EditForm_OnItemValidation; mShippingOptionObj = EditedObjectParent as ShippingOptionInfo; if (mShippingOptionObj != null) { // Register check permissions EditForm.OnCheckPermissions += (s, args) => CheckConfigurationModification(); } else { // Invalid shipping option EditedObject = null; return; } ShippingCostInfo shippingCostObj = EditedObject as ShippingCostInfo; if (shippingCostObj != null) { // Check if edited shipping cost is assigned to shipping option if ((shippingCostObj.ShippingCostID != 0) && (shippingCostObj.ShippingCostShippingOptionID != mShippingOptionObj.ShippingOptionID)) { EditedObject = null; } // Check if not editing object from another site CheckEditedObjectSiteID(mShippingOptionObj.ShippingOptionSiteID); // Check presence of main currency CheckMainCurrency(mShippingOptionObj.ShippingOptionSiteID); } }
/// <summary> /// Adds shipping cost to shipping option. Called when the "Add shipping cost" button is pressed. /// Expects the CreateShippingOption method to be run first. /// </summary> private bool AddShippingCostToOption() { // Get the shipping option ShippingOptionInfo option = ShippingOptionInfoProvider.GetShippingOptionInfo("MyNewOption", CMSContext.CurrentSiteName); if (option != null) { // Create new shipping cost object ShippingCostInfo cost = new ShippingCostInfo(); // Set the properties cost.ShippingCostMinWeight = 10; cost.ShippingCostValue = 9.9; cost.ShippingCostShippingOptionID = option.ShippingOptionID; // Set the shipping cost ShippingCostInfoProvider.SetShippingCostInfo(cost); return true; } return false; }
/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { // No option to save under if (mShippingOptionInfoObj == null) { return; } // Check permissions CheckConfigurationModification(mShippingOptionInfoObj.ShippingOptionSiteID); // True if there is already same min count; bool isMinCountUnique = false; // Server side validation of user input string errorMessage = new Validator().NotEmpty(txtShippingCostMinWeight.Text.Trim(), "com.shippingcost.minweightempty").Result; if (errorMessage == "") { errorMessage = txtShippingCostCharge.ValidatePrice(false); } double minWeight = ValidationHelper.GetDouble(txtShippingCostMinWeight.Text.Trim(), 0); if ((errorMessage == "") && (minWeight <= 0)) { errorMessage = GetString("com.shippingcost.minweightrange"); } if (errorMessage == "") { ShippingCostInfo shippingCostObj = ShippingCostInfoProvider.GetShippingCostInfo(mShippingCostId); // If ShippingCost doesnt already exist, create new one if (shippingCostObj == null) { // Create new shipping cost shippingCostObj = new ShippingCostInfo(); shippingCostObj.ShippingCostShippingOptionID = mShippingOptionId; } // Look for record with same minimum weight DataSet ds = ShippingCostInfoProvider.GetShippingCosts("ShippingCostMinWeight = " + minWeight + " AND ShippingCostShippingOptionID = " + mShippingOptionId, null, 1, "ShippingCostID"); if (DataHelper.DataSourceIsEmpty(ds)) { isMinCountUnique = true; } // Check if min weight is unique or it is update of existing item if ((isMinCountUnique) || (SqlHelperClass.GetInteger(ds.Tables[0].Rows[0]["ShippingCostID"], -1) == shippingCostObj.ShippingCostID)) { // Set ShippingCostObj values shippingCostObj.ShippingCostValue = txtShippingCostCharge.Value; shippingCostObj.ShippingCostMinWeight = minWeight; // Set data to database ShippingCostInfoProvider.SetShippingCostInfo(shippingCostObj); string redirectUrl = "ShippingOption_Edit_ShippingCosts_Edit.aspx?shippingCostId=" + Convert.ToString(shippingCostObj.ShippingCostID) + "&saved=1&shippingCostShippingOptionId=" + mShippingOptionId + "&siteId=" + SiteID; URLHelper.Redirect(redirectUrl); } else { lblError.Text = GetString("com.ui.shippingcost.edit_costexists"); lblError.Visible = true; } } else { lblError.Visible = true; lblError.Text = errorMessage; } }
/// <summary> /// Load data of editing ShippingCost. /// </summary> /// <param name="shippingCostObj">ShippingCost object</param> protected void LoadData(ShippingCostInfo shippingCostObj) { // Load data from database txtShippingCostCharge.Value = shippingCostObj.ShippingCostValue; txtShippingCostMinWeight.Text = Convert.ToString(shippingCostObj.ShippingCostMinWeight); }
protected void Page_Load(object sender, EventArgs e) { // Init labels lblShippingCostValue.Text = GetString("com.shippingcost.costlabel"); lblShippingCostMinWeight.Text = GetString("com.shippingcost.minweightlabel"); rfvMinWeight.ErrorMessage = GetString("com.shippingcost.minweightempty"); rvMinWeight.ErrorMessage = GetString("com.shippingcost.minweightrange"); txtShippingCostCharge.EmptyErrorMessage = GetString("com.shippingcost.costempty"); txtShippingCostCharge.ValidationErrorMessage = GetString("com.shippingcost.costrange"); // Get parameters from querystring mShippingCostId = QueryHelper.GetInteger("shippingCostId", 0); mShippingOptionId = QueryHelper.GetInteger("shippingCostShippingOptionId", 0); // Check if configured shipping option record belongs to correct site mShippingOptionInfoObj = ShippingOptionInfoProvider.GetShippingOptionInfo(mShippingOptionId); if (mShippingOptionInfoObj != null) { CheckEditedObjectSiteID(mShippingOptionInfoObj.ShippingOptionSiteID); txtShippingCostCharge.CurrencySiteID = mShippingOptionInfoObj.ShippingOptionSiteID; // Check presence of main currency string currencyWarning = CheckMainCurrency(mShippingOptionInfoObj.ShippingOptionSiteID); if (!string.IsNullOrEmpty(currencyWarning)) { ShowWarning(currencyWarning, null, null); } } string[,] breadcrumbs = new string[2, 4]; breadcrumbs[0, 0] = GetString("com.ui.shippingcost"); breadcrumbs[0, 1] = ResolveUrl("ShippingOption_Edit_ShippingCosts.aspx?shippingoptionid=" + mShippingOptionId + "&siteId=" + SiteID); // If true, then we will edit existing record if (mShippingCostId > 0) { // Check if there is already ShippingCostInfo with this shippingCostID ShippingCostInfo shippingCostInfo = ShippingCostInfoProvider.GetShippingCostInfo(mShippingCostId); // Check if shipping cost belongs to edited shipping option if ((shippingCostInfo != null) && (shippingCostInfo.ShippingCostShippingOptionID != mShippingOptionId)) { shippingCostInfo = null; } EditedObject = shippingCostInfo; if (shippingCostInfo != null) { // Fill editing form with existing data when not postback if (!RequestHelper.IsPostBack()) { LoadData(shippingCostInfo); // Show that the shippingCost was created or updated successfully if (QueryHelper.GetString("saved", "") == "1") { // Show message ShowChangesSaved(); } } } // Set title to "shipping cost properties" breadcrumbs[1, 0] = GetString("com.ui.shippingcost.edit"); breadcrumbs[1, 1] = ""; } // Do this when creating new cost else { // Set header to "new item" breadcrumbs[1, 0] = GetString("com.ui.shippingcost.edit_new"); } CurrentMaster.Title.Breadcrumbs = breadcrumbs; }
/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { // No option to save under if (mShippingOptionInfoObj == null) { return; } // Check permissions CheckConfigurationModification(mShippingOptionInfoObj.ShippingOptionSiteID); // True if there is already same min count; bool isMinCountUnique = false; // Server side validation of user input string errorMessage = new Validator().NotEmpty(txtShippingCostMinWeight.Text.Trim(), "com.shippingcost.minweightempty").Result; if (errorMessage == "") { errorMessage = txtShippingCostCharge.Validate(false); } double minWeight = ValidationHelper.GetDouble(txtShippingCostMinWeight.Text.Trim(), 0); if ((errorMessage == "") && (minWeight <= 0)) { errorMessage = GetString("com.shippingcost.minweightrange"); } if (errorMessage == "") { ShippingCostInfo shippingCostObj = ShippingCostInfoProvider.GetShippingCostInfo(mShippingCostId); // If ShippingCost doesn't already exist, create new one if (shippingCostObj == null) { // Create new shipping cost shippingCostObj = new ShippingCostInfo(); shippingCostObj.ShippingCostShippingOptionID = mShippingOptionId; } // Look for record with same minimum weight DataSet ds = ShippingCostInfoProvider.GetShippingCosts("ShippingCostMinWeight = " + minWeight + " AND ShippingCostShippingOptionID = " + mShippingOptionId, null, 1, "ShippingCostID"); if (DataHelper.DataSourceIsEmpty(ds)) { isMinCountUnique = true; } // Check if min weight is unique or it is update of existing item if ((isMinCountUnique) || (ValidationHelper.GetInteger(ds.Tables[0].Rows[0]["ShippingCostID"], -1) == shippingCostObj.ShippingCostID)) { // Set ShippingCostObj values shippingCostObj.ShippingCostValue = txtShippingCostCharge.Price; shippingCostObj.ShippingCostMinWeight = minWeight; // Set data to database ShippingCostInfoProvider.SetShippingCostInfo(shippingCostObj); string redirectUrl = "ShippingOption_Edit_ShippingCosts_Edit.aspx?shippingCostId=" + Convert.ToString(shippingCostObj.ShippingCostID) + "&saved=1&shippingCostShippingOptionId=" + mShippingOptionId + "&siteId=" + SiteID; URLHelper.Redirect(redirectUrl); } else { // Show error message ShowError(GetString("com.ui.shippingcost.edit_costexists")); } } else { // Show error message ShowError(errorMessage); } }
/// <summary> /// Load data of editing ShippingCost. /// </summary> /// <param name="shippingCostObj">ShippingCost object</param> protected void LoadData(ShippingCostInfo shippingCostObj) { // Load data from database txtShippingCostCharge.Price = shippingCostObj.ShippingCostValue; txtShippingCostMinWeight.Text = Convert.ToString(shippingCostObj.ShippingCostMinWeight); }