当前位置: 首页>>代码示例>>C#>>正文


C# Products.saveProduct方法代码示例

本文整理汇总了C#中Products.saveProduct方法的典型用法代码示例。如果您正苦于以下问题:C# Products.saveProduct方法的具体用法?C# Products.saveProduct怎么用?C# Products.saveProduct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Products的用法示例。


在下文中一共展示了Products.saveProduct方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Button1_Click

    /// <summary>
    /// Edits the current Product and makes the validations.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Button1_Click(object sender, EventArgs e)
    {
        Boolean flag1 = false, flag2 = false, flag3 = false, flag4 = false;
        int idProduct = Convert.ToInt16(HiddenField1.Value);
        int idPresentation = Convert.ToUInt16(DropDownList1.SelectedValue);
        string Name = Security.cleanSQL(TextBox1.Text);
        string Description = Security.cleanSQL(TextBox4.Text);
        DateTime FirstDate = DateTime.Now;
        int Amount = 0;
        double Price = 0;
        DateTime ExpirationDate = Convert.ToDateTime("01/01/1985 00:00:00");

        try
        {
            if (Security.isEmpty(Name))
            {
                throw new Exception("1");
            }
            else if (Security.isEmpty(Description))
            {
                throw new Exception("2");

            }

            flag4 = true;

            try
            {
                Amount = Convert.ToInt16(TextBox2.Text);
                flag1 = true;
                try
                {
                    Price = Convert.ToDouble(TextBox3.Text);
                    flag2 = true;
                    try
                    {
                        ExpirationDate = Convert.ToDateTime(TextBox5.Text);
                        flag3 = true;
                    }
                    catch (Exception ex)
                    {
                        this.setNotification("warning", "¡Fecha inválida!", "La fecha de caducidad ingresada no es válida...");
                        flag3 = false;
                    }
                }
                catch (Exception ex)
                {
                    this.setNotification("warning", "¡Precio inválido!", "El precio ingresado no es válido...");
                    flag2 = false;
                }
            }
            catch (Exception ex)
            {
                this.setNotification("warning", "¡Cantidad inválida!", "La cantidad ingresada no es válida...");
                flag1 = false;
            }
        }
        catch (Exception ex)
        {
            if (ex.Message == "1")
            {
                this.setNotification("warning", "¡No hay nombre!", "Ingrese un nombre de producto por favor...");
            }
            else if (ex.Message == "2")
            {
                this.setNotification("warning", "¡No hay descripción!", "Ingrese una descripción por favor...");
            }
            flag4 = false;
        }

        if (flag1 && flag2 && flag3 && flag4)
        {
            Products product = new Products(idProduct, idPresentation, Name, Amount, Price, Description, FirstDate, ExpirationDate);

            int result = product.saveProduct();

            switch (result)
            {
                case 1:
                    Response.Redirect(webURL + "views/products/editproduct.aspx?id=" + idProduct + "&action=notify&nid=" + 1, false);
                    break;
                case -1:
                    this.setNotification("warning", "¡Campo(s) repetido(s)!", "Ya existe un producto registrado con ese nombre y presentación...");
                    break;
                case 0:
                    this.setNotification("error", "¡Ooooops!", "No existe el producto...");
                    break;
                default:
                    this.setNotification("error", "¡Ooooops!", "Algo salio mal...");
                    break;
            }
        }
    }
开发者ID:efigarolam,项目名称:Snackthat,代码行数:98,代码来源:editproduct.aspx.cs


注:本文中的Products.saveProduct方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。