protected void GuardarButton2_Click(object sender, EventArgs e)
        {
            //Repositorio<Facturas> repositorio = new Repositorio<Facturas>();
            FacturaRepositorio repositorio = new FacturaRepositorio();
            Facturas           factura     = repositorio.Buscar(ToInt(FacturaIdTextBox.Text));


            if (factura == null)
            {
                if (repositorio.Guardar(LlenaClase()))
                {
                    CallModal("Factura Guardada");
                    Limpiar();
                }
                else
                {
                    CallModal("No se pudo guardar la Factura");
                    Limpiar();
                }
            }
            else
            {
                if (repositorio.Modificar(LlenaClase()))
                {
                    CallModal("Factura Modificada");
                    Limpiar();
                }
                else
                {
                    CallModal("No se modifico");
                    Limpiar();
                }
            }
        }
        private bool ExisteEnLaBaseDeDatos()
        {
            FacturaRepositorio repositorio = new FacturaRepositorio();

            Factura factura = repositorio.Buscar((int)IdNumericUpDown.Value);

            return(factura != null);
        }
Esempio n. 3
0
        protected void GuardarButton_Click(object sender, EventArgs e)
        {
            bool paso = false;
            FacturaRepositorio repositorio = new FacturaRepositorio();
            Facturas           factura     = new Facturas();

            if (HayErrores())
            {
                return;
            }
            else
            {
                factura = LlenarClase();

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

                    if (factura != null)
                    {
                        paso = repository.Modificar(LlenarClase());
                        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. 4
0
        protected void BuscarButton_Click(object sender, EventArgs e)
        {
            FacturaRepositorio repositorio = new FacturaRepositorio();

            var factura = repositorio.Buscar(Utils.ToInt(FacturaIdTextbox.Text));

            if (factura != null)
            {
                LlenarCampos(factura);
                Utils.ShowToastr(this, "Busqueda exitosa", "Exito", "success");
            }
            else
            {
                LimpiaObjetos();
                Utils.ShowToastr(this, "No se pudo encontrar la factura especificada", "Error", "error");
            }
        }
        private void BuscarButton_Click(object sender, EventArgs e)
        {
            FacturaRepositorio repositorio = new FacturaRepositorio();

            int id;

            int.TryParse(Convert.ToString(IdNumericUpDown.Value), out id);

            Factura factura = repositorio.Buscar(id);

            Limpiar();

            if (factura != null)
            {
                LlenaCampo(factura);
            }
            else
            {
                MessageBox.Show("Factura no encontrada");
            }
        }
        private void BorrarButton_Click(object sender, EventArgs e)
        {
            FacturaRepositorio repositorio = new FacturaRepositorio();

            int id;

            int.TryParse(Convert.ToString(IdNumericUpDown.Value), out id);

            Factura factura = repositorio.Buscar(id);

            Limpiar();

            if (factura != null)
            {
                repositorio.Eliminar(id);
                MessageBox.Show("Factura eliminada", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MyErrorProvider.SetError(IdNumericUpDown, "No se puede eliminar una factura que no existe");
            }
        }
Esempio n. 7
0
        protected void EliminarButton_Click(object sender, EventArgs e)
        {
            FacturaRepositorio repositorio = new FacturaRepositorio();
            int id = Utils.ToInt(FacturaIdTextbox.Text);

            var factura = repositorio.Buscar(id);

            if (factura != null)
            {
                if (repositorio.Eliminar(id))
                {
                    Utils.ShowToastr(this, "Eliminado", "Exito", "success");
                    LimpiaObjetos();
                }
                else
                {
                    Utils.ShowToastr(this, "No se pudo eliminar", "Error", "error");
                }
            }
            else
            {
                Utils.ShowToastr(this, "No existe", "Error", "error");
            }
        }
Esempio n. 8
0
        protected void LinkButton_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                /*if (FacturaGridView.Rows.Count != 0)
                 * {
                 *  factura.Detalles = (List<FacturasDetalles>)ViewState["FDetalle"];
                 *
                 * }
                 *
                 * var facturas = FacturaRepositorio.Buscar(Utils.ToInt(FacturaIdTextBox.Text));
                 *
                 * if(facturas == null)
                 * {
                 *   if(factura.Detalles.Exists(x=> x.ProductoId.Equals(Utils.ToInt(ProductoDropDownList.SelectedValue))))
                 *   {
                 *       var producto = factura.Detalles.Where(x => x.ProductoId.Equals(Utils.ToInt(ProductoDropDownList.SelectedValue)));
                 *
                 *   }
                 *
                 *   if (((FacturasDetalles)ViewState["Detalle"]).Id != 0)
                 *   {
                 *       factura.Detalles.Add(new FacturasDetalles(((FacturasDetalles)ViewState["Detalle"]).Id, Utils.ToInt(FacturaIdTextBox.Text), Utils.ToInt(ProductoDropDownList.SelectedValue), ProductoDropDownList.Text, Utils.ToInt(CantidadTextBox.Text), Utils.ToDecimal(PrecioTextBox.Text), Utils.ToDecimal(ImporteTextBox.Text)));
                 *   }
                 *   else
                 *       factura.Detalles.Add(new FacturasDetalles(0, Utils.ToInt(FacturaIdTextBox.Text), Utils.ToInt(ProductoDropDownList.SelectedValue), ProductoDropDownList.SelectedItem.ToString(), Utils.ToInt(CantidadTextBox.Text), Utils.ToDecimal(PrecioTextBox.Text), Utils.ToDecimal(ImporteTextBox.Text)));
                 *   ViewState["Detalle"] = new FacturasDetalles();
                 * }
                 * else
                 * {
                 *   factura.Detalles.Add(new FacturasDetalles(0, Utils.ToInt(FacturaIdTextBox.Text), Utils.ToInt(ProductoDropDownList.SelectedValue), ProductoDropDownList.SelectedItem.ToString(), Utils.ToInt(CantidadTextBox.Text), Utils.ToDecimal(PrecioTextBox.Text), Utils.ToDecimal(ImporteTextBox.Text)));
                 *   ViewState["Detalle"] = factura.Detalles;
                 * }
                 * //SubTotal();
                 * FacturaGridView.DataSource = ViewState["Detalle"];
                 * FacturaGridView.DataBind();*/


                var facturaAnt = FacturaRepositorio.Buscar(Utils.ToInt(FacturaIdTextBox.Text));

                if (facturaAnt == null)
                {
                    Utils.MostrarMensaje(this, "Agregado", "Exito!!", "info");
                    factura = (Facturas)ViewState["Factura"];
                    factura.AgregarDetalle(0, Utils.ToInt(FacturaIdTextBox.Text), Utils.ToInt(ProductoDropDownList.SelectedValue), ProductoDropDownList.SelectedItem.ToString(), Utils.ToInt(CantidadTextBox.Text), Utils.ToDecimal(PrecioTextBox.Text), Utils.ToDecimal(ImporteTextBox.Text));
                }
                else
                {
                    Utils.MostrarMensaje(this, "Agregado", "Exito!!", "info");
                    facturaAnt = (Facturas)ViewState["Modificar"];
                    facturaAnt.Detalles.Add(new FacturasDetalles(0, Utils.ToInt(FacturaIdTextBox.Text), Utils.ToInt(ProductoDropDownList.SelectedValue), ProductoDropDownList.SelectedItem.ToString(), Utils.ToInt(CantidadTextBox.Text), Utils.ToDecimal(PrecioTextBox.Text), Utils.ToDecimal(ImporteTextBox.Text)));
                    //factura.AgregarDetalle(0, Utils.ToInt(FacturaIdTextBox.Text), Utils.ToInt(ProductoDropDownList.SelectedValue), ProductoDropDownList.SelectedItem.ToString(), Utils.ToInt(CantidadTextBox.Text), Utils.ToDecimal(PrecioTextBox.Text), Utils.ToDecimal(ImporteTextBox.Text));
                }
                ViewState["Factura"] = factura;
                this.BindGrid();
                SubTotal();

                //aqui

                /*Utils.MostrarMensaje(this, "Agregado", "Exito!!", "info");
                 *   factura = (Facturas)ViewState["Factura"];
                 *   factura.AgregarDetalle(0, Utils.ToInt(FacturaIdTextBox.Text), Utils.ToInt(ProductoDropDownList.SelectedValue), ProductoDropDownList.SelectedItem.ToString(), Utils.ToInt(CantidadTextBox.Text), Utils.ToDecimal(PrecioTextBox.Text), Utils.ToDecimal(ImporteTextBox.Text));
                 *
                 *   ViewState["Factura"] = factura;
                 *   this.BindGrid();
                 *   SubTotal();*/
                //aqui nitido



                /*detalles.Add(new FacturasDetalles(
                 *  id: 0,
                 *  facturaId: Utils.ToInt(FacturaIdTextBox.Text),
                 *  productoId: Utils.ToInt(ProductoDropDownList.SelectedValue),
                 *  descripcion: ProductoDropDownList.Text,
                 *  cantidad: Utils.ToInt(CantidadTextBox.Text),
                 *  precio: Utils.ToDecimal(PrecioTextBox.Text),
                 *  importe: Utils.ToDecimal(ImporteTextBox.Text)
                 *  ));*/

                //SubTotal();
            }
        }