예제 #1
0
    /// <summary>
    /// Assigns the selected Products to the selected Seller
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Button1_Click(object sender, EventArgs e)
    {
        int idSeller = 0;
        try
        {
            idSeller = Convert.ToInt16(DropDownList1.SelectedValue.ToString());
        }
        catch (Exception ex)
        {
            idSeller = 0;
        }

        string idProducts = Page.Request["Productos"];
        string Amounts = Page.Request["Cantidad"];
        string[] aidProducts;
        string[] aAmounts;

        try
        {
            aidProducts = idProducts.Split(new char[] { ',' });
        }
        catch(Exception ex)
        {
            aidProducts = new string[0];
        }

        try
        {
            aAmounts = Amounts.Split(new char[] { ',' });
        }
        catch(Exception ex)
        {
            aAmounts = new string[0];
        }

        if (idSeller == 0)
        {
            this.setNotification("error", "¡Ooooops!", "Selecciona un vendedor...");
        }
        else if (aidProducts.Length == 0)
        {
            this.setNotification("warning", "¡No hay productos seleccionados!", "Selecciona un producto como mínimo...");
        }
        else if (aidProducts.Length != aAmounts.Length)
        {
            this.setNotification("error", "¡Ooooops!", "No hay el mismo número de productos seleccionados que cantidades...");
        }
        else
        {
            Products products = new Products();
            products.assignProducts(idSeller, aidProducts, aAmounts);
            this.setNotification("success", "¡Éxito!", "Los productos han sido asignados");
        }
    }