private void BindShippingRates() { ShippingController controller = new ShippingController(); ArrayList shippingRates = controller.GetAllShippingRates(parentControl.PortalId); grdShippingRates.DataSource = shippingRates; grdShippingRates.DataBind(); }
private void btnSaveShippingFee_Click(object sender, EventArgs e) { // Loop through the items in the datagrid. ShippingController controller = new ShippingController(); ExpandShippingAdmin(); foreach (DataGridItem di in grdShippingRates.Items) { // Make sure this is an item and not the header or footer. if (di.ItemType == ListItemType.Item || di.ItemType == ListItemType.AlternatingItem) { // Get the current row for update or delete operations later. int ID = (int)grdShippingRates.DataKeys[di.ItemIndex]; // See if this one needs to be deleted. if (((CheckBox)di.FindControl("chkDelete")).Checked) { controller.DeleteShippingRate(ID); } else { // Update the row instead. ShippingInfo shippingInfo = new ShippingInfo(); shippingInfo.ID = ID; // Ajouté : Localisation des messages d'erreur if (((TextBox)di.FindControl("lblDescription")).Text.Length == 0) { ShowError(Localization.GetString("ErrorRateDescription", this.LocalResourceFile), ((TextBox)di.FindControl("lblDescription"))); return; } shippingInfo.Description = ((TextBox)di.FindControl("lblDescription")).Text; ClearError(((TextBox)di.FindControl("lblDescription"))); try { shippingInfo.MinWeight = Decimal.Parse(((TextBox)di.FindControl("lblMinWeight")).Text); ClearError(((TextBox)di.FindControl("lblMinWeight"))); } catch (Exception) { ShowError(Localization.GetString("ErrorMinWeight", this.LocalResourceFile), ((TextBox)di.FindControl("lblMinWeight"))); return; } try { shippingInfo.MaxWeight = Decimal.Parse(((TextBox)di.FindControl("lblMaxWeight")).Text); ClearError(((TextBox)di.FindControl("lblMaxWeight"))); } catch (Exception) { ShowError(Localization.GetString("ErrorMaxWeight", this.LocalResourceFile), ((TextBox)di.FindControl("lblMaxWeight"))); return; } try { shippingInfo.Cost = Decimal.Parse(((TextBox)di.FindControl("lblCost")).Text); ClearError(((TextBox)di.FindControl("lblCost"))); } catch (Exception) { ShowError(Localization.GetString("ErrorCost", this.LocalResourceFile), ((TextBox)di.FindControl("lblCost"))); return; } controller.UpdateShippingRate(shippingInfo); } } } BindShippingRates(); lblError.Visible = false; }
private void grdShippingRates_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { // Add the new item to the dataset. I use an array here for efficiency. if (e.CommandName == "Add") { // Ajouté : Localisation des messages d'erreur ExpandShippingAdmin(); ShippingInfo newShippingInfo = new ShippingInfo(); if (((TextBox)e.Item.FindControl("txtNewDescription")).Text.Length == 0) { ShowError(Localization.GetString("ErrorRateDescription", this.LocalResourceFile), ((TextBox)e.Item.FindControl("txtNewDescription"))); return; } newShippingInfo.Description = ((TextBox)e.Item.FindControl("txtNewDescription")).Text; ClearError(((TextBox)e.Item.FindControl("txtNewDescription"))); try { newShippingInfo.MinWeight = Decimal.Parse(((TextBox)e.Item.FindControl("txtNewMinWeight")).Text); ClearError(((TextBox)e.Item.FindControl("txtNewMinWeight"))); } catch (Exception) { ShowError(Localization.GetString("ErrorMinWeight", this.LocalResourceFile), ((TextBox)e.Item.FindControl("txtNewMinWeight"))); return; } try { newShippingInfo.MaxWeight = Decimal.Parse(((TextBox)e.Item.FindControl("txtNewMaxWeight")).Text); ClearError(((TextBox)e.Item.FindControl("txtNewMaxWeight"))); } catch (Exception) { ShowError(Localization.GetString("ErrorMaxWeight", this.LocalResourceFile), ((TextBox)e.Item.FindControl("txtNewMaxWeight"))); return; } try { newShippingInfo.Cost = Decimal.Parse(((TextBox)e.Item.FindControl("txtNewCost")).Text); ClearError(((TextBox)e.Item.FindControl("txtNewCost"))); } catch (Exception) { ShowError(Localization.GetString("ErrorCost", this.LocalResourceFile), ((TextBox)e.Item.FindControl("txtNewCost"))); return; } ShippingController controller = new ShippingController(); controller.AddShippingRate(PortalId, newShippingInfo); BindShippingRates(); lblError.Visible = false; } }