Example #1
0
    protected void uxGrid_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        try
        {
            string zoneGroupID = ((Label)uxGrid.Rows[e.RowIndex].FindControl("uxZoneGroupIDLabel")).Text;
            string name        = ((TextBox)uxGrid.Rows[e.RowIndex].FindControl("uxNameText")).Text;

            if (!String.IsNullOrEmpty(zoneGroupID))
            {
                ShippingZoneGroup zoneGroup = new ShippingZoneGroup();
                zoneGroup.ZoneName    = name;
                zoneGroup.ZoneGroupID = zoneGroupID;
                DataAccessContext.ShippingZoneGroupRepository.Save(zoneGroup);
            }

            // End editing
            uxGrid.EditIndex = -1;
            RefreshGrid();

            uxMessage.DisplayMessage(Resources.ShippingZoneMessages.UpdateSuccess);
        }
        catch (Exception ex)
        {
            uxMessage.DisplayException(ex);
        }
        finally
        {
            // Avoid calling Update() automatically by GridView
            e.Cancel = true;
        }
    }
Example #2
0
    private void CreateDummyRow(IList <ShippingZoneGroup> list)
    {
        ShippingZoneGroup zoneGroup = new ShippingZoneGroup();

        zoneGroup.ZoneGroupID = "-1";
        list.Add(zoneGroup);
    }
    protected void uxGrid_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        try
        {
            string id          = ((Label)uxGrid.Rows[e.RowIndex].FindControl("uxZoneItemIDLabel")).Text.Trim();
            string countryCode = ((AdminAdvanced_Components_CountryList)uxGrid.Rows[e.RowIndex].FindControl("uxCountryList")).CurrentSelected;
            string stateCode   = ((AdminAdvanced_Components_StateList)uxGrid.Rows[e.RowIndex].FindControl("uxStateList")).CurrentSelected;
            string zipCode     = ((TextBox)uxGrid.Rows[e.RowIndex].FindControl("uxZipCodeEditText")).Text.Trim();

            if (!String.IsNullOrEmpty(id))
            {
                if (IsZipcodeFormatCorrect(zipCode))
                {
                    ShippingZoneItem  currentItem = new ShippingZoneItem();
                    ShippingZoneGroup zoneGroup   = DataAccessContext.ShippingZoneGroupRepository.GetOne(ZoneGroupID);

                    foreach (ShippingZoneItem item in zoneGroup.ZoneItem)
                    {
                        if (item.ZoneItemID == id)
                        {
                            currentItem.ZoneItemID  = id;
                            currentItem.CountryCode = countryCode;
                            currentItem.StateCode   = stateCode;
                            currentItem.ZipCode     = zipCode;

                            if (!IsExistItem(currentItem))
                            {
                                item.CountryCode = countryCode;
                                item.StateCode   = stateCode;
                                item.ZipCode     = zipCode;
                                DataAccessContext.ShippingZoneGroupRepository.Save(zoneGroup);
                                uxMessage.DisplayMessage(Resources.ShippingZoneMessages.UpdateZoneItemSuccess);
                            }
                            else
                            {
                                uxMessage.DisplayError(Resources.ShippingZoneMessages.AddErrorDuplicatedItem);
                            }
                        }
                    }
                }
                else
                {
                    uxMessage.DisplayError(Resources.ShippingZoneMessages.ZipCodeFormatIncorrect);
                }
            }

            // End editing
            uxGrid.EditIndex = -1;
            RefreshGrid();
        }
        catch (Exception ex)
        {
            uxMessage.DisplayException(ex);
        }
        finally
        {
            // Avoid calling Update() automatically by GridView
            e.Cancel = true;
        }
    }
Example #4
0
    protected void uxGrid_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        try
        {
            if (e.CommandName == "Add")
            {
                string name = ((TextBox)uxGrid.FooterRow.FindControl("uxNameText")).Text;

                ShippingZoneGroup zoneGroup = new ShippingZoneGroup();
                zoneGroup.ZoneName = name;

                DataAccessContext.ShippingZoneGroupRepository.Save(zoneGroup);

                ((TextBox)uxGrid.FooterRow.FindControl("uxNameText")).Text = "";

                uxMessage.DisplayMessage(Resources.ShippingZoneMessages.AddSuccess);

                RefreshGrid();
            }

            else if (e.CommandName == "Edit")
            {
                uxGrid.ShowFooter   = false;
                uxAddButton.Visible = true;
            }
        }
        catch (Exception ex)
        {
            uxMessage.DisplayException(ex);
        }
    }
    protected void uxDeleteButton_Click(object sender, EventArgs e)
    {
        bool deleted = false;

        foreach (GridViewRow row in uxGrid.Rows)
        {
            CheckBox deleteCheck = (CheckBox)row.FindControl("uxCheck");
            if (deleteCheck != null && deleteCheck.Checked)
            {
                string            id        = uxGrid.DataKeys[row.RowIndex]["ZoneItemID"].ToString();
                ShippingZoneGroup zoneGroup = DataAccessContext.ShippingZoneGroupRepository.GetOne(ZoneGroupID);
                zoneGroup = RemoveItem(zoneGroup, id);
                DataAccessContext.ShippingZoneGroupRepository.Save(zoneGroup);
                deleted = true;
            }
        }
        uxGrid.EditIndex = -1;

        if (deleted)
        {
            uxMessage.DisplayMessage(Resources.ShippingZoneMessages.DeleteSuccess);
        }

        RefreshGrid();
    }
 private ShippingZoneGroup RemoveItem(ShippingZoneGroup group, string itemID)
 {
     for (int i = 0; i < group.ZoneItem.Count; i++)
     {
         if (group.ZoneItem[i].ZoneItemID == itemID)
         {
             group.ZoneItem.RemoveAt(i);
             return(group);
         }
     }
     return(group);
 }
    protected void uxGrid_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        try
        {
            if (e.CommandName == "Add")
            {
                ShippingZoneGroup zoneGroup = DataAccessContext.ShippingZoneGroupRepository.GetOne(ZoneGroupID);
                ShippingZoneItem  item      = SetupShippingZoneItemDetails();

                if (IsZipcodeFormatCorrect(item.ZipCode))
                {
                    if (String.IsNullOrEmpty(item.CountryCode))
                    {
                        uxMessage.DisplayError(Resources.ShippingZoneMessages.AddErrorSelectCountry);
                        return;
                    }

                    if (!IsExistItem(item))
                    {
                        zoneGroup.ZoneItem.Add(item);
                        DataAccessContext.ShippingZoneGroupRepository.Save(zoneGroup);

                        uxMessage.DisplayMessage(Resources.ShippingZoneMessages.AddZoneItemSuccess);
                        RefreshGrid();
                    }
                    else
                    {
                        uxMessage.DisplayError(Resources.ShippingZoneMessages.AddErrorDuplicatedItem);
                    }

                    ((TextBox)uxGrid.FooterRow.FindControl("uxZipCodeText")).Text = "";
                }
                else
                {
                    uxMessage.DisplayError(Resources.ShippingZoneMessages.ZipCodeFormatIncorrect);
                }
            }
            if (e.CommandName == "Edit")
            {
                uxGrid.ShowFooter   = false;
                uxAddButton.Visible = true;
            }
        }
        catch (Exception ex)
        {
            uxMessage.DisplayException(ex);
        }
    }
    private bool IsExistItem(ShippingZoneItem item)
    {
        ShippingZoneGroup zoneGroup = DataAccessContext.ShippingZoneGroupRepository.GetOne(ZoneGroupID);

        foreach (ShippingZoneItem zoneItem in zoneGroup.ZoneItem)
        {
            if (zoneItem.CountryCode == item.CountryCode && zoneItem.StateCode == item.StateCode && zoneItem.ZipCode == item.ZipCode)
            {
                if (zoneItem.ZoneItemID != item.ZoneItemID)
                {
                    return(true);
                }
            }
        }

        return(false);
    }
Example #9
0
    protected void uxDeleteButton_Click(object sender, EventArgs e)
    {
        string[] checkedIDs = GetCheckedIDs();

        string containingID;

        if (ContainsShippingOptions(checkedIDs, out containingID))
        {
            ShippingZoneGroup zoneGroup = DataAccessContext.ShippingZoneGroupRepository.GetOne(containingID);
            uxMessage.DisplayError(
                Resources.ShippingZoneMessages.DeleteErrorContainingShippingOptions,
                zoneGroup.ZoneName, containingID);
        }
        else
        {
            DeleteItems(checkedIDs);
        }
    }