protected void Button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtAbono.Text))
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "SweetAlert", "vacio()", true);
            }
            else
            {
                DateTime          fechact  = DateTime.Now;
                ControllerCliente ctrlClie = new ControllerCliente();
                tblVenta          ven      = new tblVenta();
                ControllerAlmacen ctrlAlm  = new ControllerAlmacen();

                var ultimoregistro = (from ha in contexto.tblHistorialAbono
                                      where ha.fkVenta == int.Parse(Session["desgloce"].ToString())
                                      orderby ha.idHistorialAbono descending
                                      select ha).FirstOrDefault();

                var ventas = (from venta in contexto.tblVenta
                              where venta.idVenta == int.Parse(Session["desgloce"].ToString())
                              select new { fecha = venta.Fecha, fin = venta.FechaCredito, total = venta.dblTotal }).FirstOrDefault();

                var suma = ultimoregistro.dblCantidadAnterior + decimal.Parse(txtAbono.Text);

                if (suma < ventas.total)
                {
                    tblHistorialAbono HisAbo = new tblHistorialAbono();
                    HisAbo.Fecha               = fechact;
                    HisAbo.dblCantidad         = decimal.Parse(txtAbono.Text);
                    HisAbo.dblCantidadAnterior = suma;
                    HisAbo.fkVenta             = int.Parse(Session["desgloce"].ToString());
                    HisAbo.fkValidacionUsuario = int.Parse(Session["idUsuario"].ToString());

                    ctrlClie.InsertarHistorialAbono(HisAbo);
                    this.Response.Redirect("./AbonoExito.aspx", true);
                }
                else if (suma == ventas.total)
                {
                    tblHistorialAbono HisAbo = new tblHistorialAbono();
                    HisAbo.Fecha               = fechact;
                    HisAbo.dblCantidad         = decimal.Parse(txtAbono.Text);
                    HisAbo.dblCantidadAnterior = suma;
                    HisAbo.fkVenta             = int.Parse(Session["desgloce"].ToString());
                    HisAbo.fkValidacionUsuario = int.Parse(Session["idUsuario"].ToString());

                    ctrlClie.InsertarHistorialAbono(HisAbo);
                    ven.idVenta   = int.Parse(Session["desgloce"].ToString());
                    ven.strEstado = "VENTA A CREDITO FINALIZADA";

                    ctrlAlm.EditarFinalizadoCredito(ven);

                    this.Response.Redirect("./AlertaExito.aspx", true);
                }
                else
                {
                    this.Response.Redirect("./AlertaErrorAbono.aspx", true);
                }
            }
        }
Exemplo n.º 2
0
        public bool InsertarHistorialAbono(tblHistorialAbono _TBL_HistorialAbono)
        {
            bool respuesta = false;

            try
            {
                contexto.tblHistorialAbono.InsertOnSubmit(_TBL_HistorialAbono);
                contexto.SubmitChanges();
                respuesta = true;
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.ToString());
                respuesta = false;
            }
            return(respuesta);
        }
        protected void Button3_Click(object sender, EventArgs e)
        {
            CultureInfo culture = new CultureInfo("en-US");
            var         vacio   = 0.0000;

            this.Calcular();

            if (double.Parse(lblTotal2.Text) == vacio)
            {
                this.Response.Redirect("./AlertaError.aspx", true);
            }

            else
            {
                DateTime          fechact = DateTime.Now;
                ControllerCliente ctrlCli = new ControllerCliente();

                tblHistorialAbono HisAbo = new tblHistorialAbono();
                HisAbo.Fecha               = fechact;
                HisAbo.dblCantidad         = decimal.Parse(txtDinero.Text, culture);
                HisAbo.dblCantidadAnterior = decimal.Parse(txtDinero.Text, culture);
                ctrlCli.InsertarHistorialAbono(GetVenta(HisAbo));

                foreach (GridViewRow row in GridView1.Rows)
                {
                    tblDetalleVenta detalle = new tblDetalleVenta();
                    detalle.Fecha       = fechact;
                    detalle.intCantidad = int.Parse(((TextBox)row.Cells[3].FindControl("TextBox1")).Text, culture);
                    detalle.dblPrecio   = decimal.Parse(((TextBox)row.Cells[4].FindControl("TextBox2")).Text, culture);
                    detalle.fkProducto  = int.Parse(row.Cells[1].Text);
                    detalle.fkEmpleado  = int.Parse(Session["id"].ToString());
                    detalle.fkVenta     = HisAbo.fkVenta;
                    ctrlCli.InsertarDetalle(detalle);
                }

                this.Response.Redirect("./AlertaExito.aspx", true);
            }
            Response.Redirect("CreditoVenta.aspx");
        }
        protected tblHistorialAbono GetVenta(tblHistorialAbono HisVen)
        {
            CultureInfo       culture  = new CultureInfo("en-US");
            DateTime          fechact  = DateTime.Now;
            ControllerCliente ctrlClie = new ControllerCliente();

            tblVenta ven = new tblVenta();

            ven.Fecha          = fechact;
            ven.FechaCredito   = Convert.ToDateTime(txtFechaFin.Text);
            ven.dblTotal       = decimal.Parse(lblTotal2.Text);
            ven.strEstado      = "CREDITO";
            ven.fkCliente      = int.Parse(Session["cliente"].ToString());
            ven.dblInteres     = decimal.Parse(txtInteres.Text);
            ven.dblAbono       = decimal.Parse(txtDinero.Text, culture);
            ven.strFechaEntega = fechaEntrega.Text;
            ven.strHoraEntega  = txtHora.Text;

            HisVen.tblVenta = ven;



            return(HisVen);
        }