protected void guardarButton_Click(object sender, EventArgs e)
        {
            bool paso = false;
            RepositorioEntrada repositorio = new RepositorioEntrada();
            Entrada            entrada     = new Entrada();

            if (HayErrores())
            {
                return;
            }
            else
            {
                entrada = LlenaClase();

                if (entradaIdTextBox.Text == "0")
                {
                    paso = repositorio.Guardar(entrada);
                    Utils.ShowToastr(this, "Guardado", "Exito", "success");
                    LimpiaObjetos();
                }
                else
                {
                    RepositorioEntrada repository = new RepositorioEntrada();
                    int id = Utils.ToInt(entradaIdTextBox.Text);
                    entrada = repository.Buscar(id);

                    if (entrada != null)
                    {
                        paso = repository.Modificar(LlenaClase());
                        Utils.ShowToastr(this, "Modificado", "Exito", "success");
                    }
                    else
                    {
                        Utils.ShowToastr(this, "Id no existe", "Error", "error");
                    }
                }

                if (paso)
                {
                    LimpiaObjetos();
                }
                else
                {
                    Utils.ShowToastr(this, "No se pudo guardar", "Error", "error");
                }
            }
        }
Esempio n. 2
0
        protected void GuardarButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                int id = Convert.ToInt32(entradaIdTextbox.Text);
                if (!(productoIdTextbox.Text == "0" || cantidadTextbox.Text == "0" || String.IsNullOrEmpty(fechaTextbox.Text)))
                {
                    RepositorioEntrada         repositorio     = new RepositorioEntrada();
                    RepositorioBase <Producto> repositorioBase = new RepositorioBase <Producto>();
                    if (id == 0 && repositorioBase.Buscar(int.Parse(productoIdTextbox.Text)) != null)
                    {
                        repositorio.Guardar(LlenaClase());
                        ScriptManager.RegisterStartupScript(Page, typeof(Page), "toastr_message", script: "toastr['success']('Guardado con Exito');", addScriptTags: true);
                    }
                    else
                    {
                        if (repositorio.Buscar(id) != null && repositorioBase.Buscar(int.Parse(productoIdTextbox.Text)) != null)
                        {
                            EntradaProducto entrada = repositorio.Buscar(int.Parse(entradaIdTextbox.Text));

                            entrada.ProductoId = int.Parse(entradaIdTextbox.Text);
                            entrada.Fecha      = DateTime.Parse(fechaTextbox.Text);
                            entrada.Cantidad   = int.Parse(cantidadTextbox.Text);

                            repositorio.Modificar(entrada);

                            ScriptManager.RegisterStartupScript(Page, typeof(Page), "toastr_message", script: "toastr['success']('Modificado con Exito');", addScriptTags: true);
                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(Page, typeof(Page), "toastr_message", script: "toastr['error']('No existe una entrada o un producto con ese ID, no puede modificarse');", addScriptTags: true);
                        }
                    }
                }
                else if (id == 0)
                {
                    ScriptManager.RegisterStartupScript(Page, typeof(Page), "toastr_message", script: "toastr['warning']('Debe rellenar todos los campos');", addScriptTags: true);
                }
                Limpiar();
            }
        }
Esempio n. 3
0
        protected void GuadarButton_Click(object sender, EventArgs e)
        {
            RepositorioEntrada repositorio = new RepositorioEntrada();
            Entrada            factura     = repositorio.Buscar(Utils.ToInt(IdTextBox.Text));

            if (Validar())
            {
                return;
            }
            if (factura == null)
            {
                if (repositorio.Guardar(LlenarClase()))
                {
                    Utils.ShowToastr(this, "Guardado", "Exito", "success");
                    Limpiar();
                }
                else
                {
                    Utils.ShowToastr(this, "No existe", "Error", "error");
                    Limpiar();
                }
            }
            else
            {
                if (repositorio.Modificar(LlenarClase()))
                {
                    Utils.ShowToastr(this.Page, "Modificado con exito!!", "Guardado", "success");
                    Limpiar();
                }
                else
                {
                    Utils.ShowToastr(this.Page, "No se puede modificar", "Error", "error");
                    Limpiar();
                }
            }
        }