Example #1
0
        protected void btnregistrar_Click(object sender, EventArgs e)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "$('#modal-facturaregistrada').modal('show');", true);
            lblm.Text    = "Venta Registrada";
            lblm.Visible = true;
            try
            {
                string idFactura;

                lblerroregistrar.Visible = false;
                TheGym k = new TheGym
                {
                    FechaIdDetCaja = lblFecha.Text
                };
                DataTable dt = new DataTable();
                dt = k.GetEstadoDetCaja();
                if (dt.Rows.Count == 0)
                {
                    DataTable dt1 = new DataTable();
                    dt1 = k.GetEstadoDetCajaAP();

                    if (dt1.Rows.Count == 1)
                    {
                        if (CheckBox1.Checked != true)
                        {
                            k.FactVentaCliente  = id;
                            k.FactVentaEmpleado = idEmpleado;
                            k.FactVentaTotal    = GetTotal();
                            k.FactVentaFecha    = lblFecha.Text;
                            k.FactVentaHora     = lblhora.Text;

                            dt        = k.AddFacturaVenta();
                            idFactura = dt.Rows[0][0].ToString();

                            k.FactVentaFormaPago   = ddlformadepago.SelectedValue;
                            k.FactVentaComprobante = TbComprobante.Text;
                            k.FactVentaFactura     = idFactura;

                            k.AddMovimientoCajaVenta();

                            k.FactVentaSucursal = suc;
                            dt = k.AddMovStock();
                            k.FactVentaMovimiento = dt.Rows[0][0].ToString();

                            for (int i = 0; i < Tabla.Rows.Count; i++)
                            {
                                k.FactVentaProducto = Tabla.Rows[i][0].ToString();
                                k.FactVentaPrecio   = Tabla.Rows[i][3].ToString();
                                k.FactVentaCantidad = Tabla.Rows[i][2].ToString();
                                k.FactVentaSucursal = suc;

                                k.AddDetalleFacturaVenta();

                                k.AddDetMovStock();
                            }

                            //btnregistrar.Visible = false;
                            //btncancelar.Visible = false;
                            //generarPDF.Visible = true;
                            //btnuevaFactura.Visible = true;
                            //tbcliente.Text = string.Empty;
                            //CheckBox1.Checked = false;
                            //ddlformadepago.ClearSelection();
                            //lblComprobante.Visible = false;
                            //TbComprobante.Visible = false;
                            DataTable vacio = new DataTable();
                            griddetallefactura.DataSource = vacio;
                            //griddetallefactura.DataBind();
                            //griddetallefactura.Dispose();
                            //griddetallefactura.Visible = false;
                        }
                        else
                        {
                            k.FactVentaCliente  = "2107";
                            k.FactVentaEmpleado = idEmpleado;
                            k.FactVentaTotal    = GetTotal();
                            k.FactVentaFecha    = lblFecha.Text;
                            k.FactVentaHora     = lblhora.Text;

                            dt        = k.AddFacturaVenta();
                            idFactura = dt.Rows[0][0].ToString();

                            k.FactVentaFormaPago   = ddlformadepago.SelectedValue;
                            k.FactVentaComprobante = lblComprobante.Text;
                            k.FactVentaFactura     = idFactura;

                            k.AddMovimientoCajaVenta();

                            k.FactVentaSucursal = suc;
                            dt = k.AddMovStock();
                            k.FactVentaMovimiento = dt.Rows[0][0].ToString();

                            for (int i = 0; i < Tabla.Rows.Count; i++)
                            {
                                k.FactVentaProducto = Tabla.Rows[i][0].ToString();
                                k.FactVentaPrecio   = Tabla.Rows[i][3].ToString();
                                k.FactVentaCantidad = Tabla.Rows[i][2].ToString();
                                k.FactVentaSucursal = suc;

                                lblm.Text    = "Venta Registrada";
                                lblm.Visible = true;
                                ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "$('#modal-facturaregistrada').modal('show');", true);
                                k.AddDetalleFacturaVenta();

                                k.AddDetMovStock();
                            }

                            btnregistrar.Visible   = false;
                            btncancelar.Visible    = false;
                            generarPDF.Visible     = true;
                            btnuevaFactura.Visible = true;
                            tbcliente.Text         = string.Empty;
                            CheckBox1.Checked      = false;
                            ddlformadepago.ClearSelection();
                            lblComprobante.Visible = false;
                            TbComprobante.Visible  = false;
                            DataTable vacio = new DataTable();
                            griddetallefactura.DataSource = vacio;
                            griddetallefactura.DataBind();
                            griddetallefactura.Dispose();
                            griddetallefactura.Visible = false;

                            lblm.Text    = "Venta Registrada";
                            lblm.Visible = true;
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "$('#modal-facturaregistrada').modal('show');", true);
                        }
                    }
                    else
                    {
                        lblm.Visible = true;
                        lblm.Text    = "Venta Registrada";
                    }
                }
                else
                {
                    lblm.Visible = true;
                    lblm.Text    = "Venta Registrada";
                }
                lblm.Text    = "Venta Registrada";
                lblm.Visible = true;

                ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "$('#modal-facturaregistrada').modal('show');", true);
            }
            catch (Exception ex)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "$('#modal-facturaregistrada').modal('show');", true);
                lblerroregistrar.Text    = ex.Message;
                lblerroregistrar.Visible = true;
            }

            ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "$('#modal-facturaregistrada').modal('show');", true);
            //ocultamos el resto de los botones
        }