Example #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {

                decimal precio = 0;
                if (prod != null)
                {
                    dataGridView1.Rows.Clear();
                    Facturacion f = new Facturacion(0, prod, Convert.ToInt32(txtCant.Text));
                    if (listaf.Count > 0)
                    {
                        int flag = 0;
                        foreach (Facturacion fe in listaf)
                        {
                            flag = 0;
                            if (fe.P.Idproductos == prod.Idproductos)
                            {
                                fe.Cantidad = fe.Cantidad + f.Cantidad;
                                flag = 1;
                                break;
                            }
                        }
                        if (flag == 0)
                        {
                            if (f.P.Sesiones > 0 && pac != null || f.P.Sesiones == 0)
                            {
                                listaf.Add(f);
                            }
                            else
                            {
                                MessageBox.Show("Debe seleccionar un cliente para facturar un servicio");
                            }
                        }
                    }
                    else
                    {
                        if (f.P.Sesiones > 0 && pac != null || f.P.Sesiones == 0)
                        {
                            listaf.Add(f);
                        }
                        else
                        {
                            MessageBox.Show("Debe seleccionar un cliente para facturar un servicio");
                        }
                    }
                    int x = 0;
                    if (listaf.Count > 0)
                    {
                        dataGridView1.Rows.Add(listaf.Count());
                        foreach (Facturacion fa in listaf)
                        {
                            dataGridView1.Rows[x].Cells[0].Value = fa.Idfacturacion;
                            dataGridView1.Rows[x].Cells[1].Value = fa.P.Detalle;
                            dataGridView1.Rows[x].Cells[2].Value = fa.Cantidad;
                            dataGridView1.Rows[x].Cells[3].Value = fa.P.Precioventa * fa.Cantidad;
                            dataGridView1.Rows[x].Cells[4].Value = fa.P.Idproductos;
                            decimal precio1 = fa.P.Precioventa * fa.Cantidad;
                            x++;
                            precio = precio + precio1;
                        }
                        if (txtBonificacion.Text != "")
                        {
                            precio = precio - Convert.ToDecimal(txtBonificacion.Text);
                        }
                        lbltotal.Text = precio.ToString();
                        total = precio;
                    }
                }
                prod = null;
                txtCodigo.Text = "";
                txtCant.Text = "1";
                txtProducto.Text = "";
                txtPrecio.Text = "";
                button1.Focus();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         if (idfactura != 0)
         {
             DialogResult dialogResult = MessageBox.Show("Esta seguro de Anular el comprobante?", "Anula Comprobante", MessageBoxButtons.YesNo);
             if (dialogResult == DialogResult.Yes)
             {
                 Acceso_BD oc = new Acceso_BD();
                 DataTable dt = oc.leerDatos("select ifnull(t.idserviciosturnos,0) as id from facturacion f left join lineafactura l on f.idfacturacion = l.idfacturacion left join servicios s on l.idlineafactura = s.idlineafactura left join serviciosturnos t on s.idservicios = t.idservicios where f.idfacturacion = '"+idfactura+"'");
                 int id = 0;
                 foreach (DataRow dr in dt.Rows)
                 {
                     id = Convert.ToInt32(dr["id"]);
                     if (id != 0)
                     {
                         break;
                     }
                 }
                 if (id == 0)
                 {
                     dt = oc.leerDatos("select * from lineafactura where idfacturacion = '"+idfactura+"'");
                     List<Facturacion> lista = new List<Facturacion>();
                     foreach (DataRow dr in dt.Rows)
                     {
                         Productos p = new Productos(Convert.ToInt32(dr["idproductos"]), "", 0, 0, 0, 0, 0);
                         Facturacion f = new Facturacion(Convert.ToInt32(dr["idlineafactura"]), p, Convert.ToInt32(dr["cantidad"]));
                         lista.Add(f);
                     }
                     foreach (Facturacion a in lista)
                     {
                         oc.ActualizarBD("begin; update productos set stock = stock + '" + a.Cantidad + "' where idproductos = '" + a.P.Idproductos + "' and sesiones = 0; delete from servicios where idlineafactura = '"+a.Idfacturacion+"'; delete from lineafactura where idlineafactura = '"+a.Idfacturacion+"'; commit;");
                     }
                     oc.ActualizarBD("begin; delete from formasdepago where idfacturacion = '"+idfactura+"'; delete from facturacion where idfacturacion = '" + idfactura + "'; commit;");
                     MessageBox.Show("Comprobante eliminado exitosamente");
                 }
                 else
                 {
                     MessageBox.Show("Imposible eliminar comprobante, servicios ya asignados a turnos");
                 }
             }
         }
         else
         {
             MessageBox.Show("Debe primero traer un comprobante valido");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Example #3
0
 private void button3_Click(object sender, EventArgs e)
 {
     int fila = dataGridView1.CurrentRow.Index;
     decimal precio = 0;
     if (dataGridView1.Rows[fila].Cells[1].Value.ToString() != "")
     {
         DialogResult dialogResult = MessageBox.Show("Esta seguro de eliminar el producto: " + dataGridView1.Rows[fila].Cells[1].Value.ToString(), "Eliminar producto de facturacion", MessageBoxButtons.YesNo);
         if (dialogResult == DialogResult.Yes)
         {
             int flag = 0;
             Facturacion fa = new Facturacion(0, null, 0);
             foreach (Facturacion fe in listaf)
             {
                 if (fe.P.Idproductos == Convert.ToInt32(dataGridView1.Rows[fila].Cells[4].Value))
                 {
                     flag = 1;
                     fa = fe;
                     break;
                 }
             }
             if (flag == 1)
             {
                 listaf.Remove(fa);
             }
             dataGridView1.Rows.Clear();
             int x = 0;
             if (listaf.Count > 0)
             {
                 dataGridView1.Rows.Add(listaf.Count());
                 foreach (Facturacion fac in listaf)
                 {
                     dataGridView1.Rows[x].Cells[0].Value = fac.Idfacturacion;
                     dataGridView1.Rows[x].Cells[1].Value = fac.P.Detalle;
                     dataGridView1.Rows[x].Cells[2].Value = fac.Cantidad;
                     dataGridView1.Rows[x].Cells[3].Value = fac.P.Precioventa * fac.Cantidad;
                     dataGridView1.Rows[x].Cells[4].Value = fac.P.Idproductos;
                     decimal precio1 = fac.P.Precioventa * fac.Cantidad;
                     x++;
                     precio = precio + precio1;
                 }
                 lbltotal.Text = precio.ToString();
             }
         }
     }
 }