예제 #1
0
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                SqlConnection conexion = new SqlConnection(database);
                conexion.Open();
                string     inserta_factura = "insert into tabla_factura(Codigo,Detalle,ValorUnitario,Cantidad,ValorTotal) values(@Codigo,@Detalle,@ValorUnitario,@Cantidad,@ValorTotal) ";
                SqlCommand comando         = new SqlCommand(inserta_factura, conexion);

                foreach (DataGridViewRow row in dataGridView_tabla.Rows)
                {
                    comando.Parameters.Clear();
                    comando.Parameters.AddWithValue("@Codigo", Convert.ToString(row.Cells["Codigo"].Value));
                    comando.Parameters.AddWithValue("@Detalle", Convert.ToString(row.Cells["Detalle"].Value));
                    comando.Parameters.AddWithValue("@ValorUnitario", Convert.ToString(row.Cells["Valor Unitario"].Value));
                    comando.Parameters.AddWithValue("@Cantidad", Convert.ToString(row.Cells["Cantidad"].Value));
                    comando.Parameters.AddWithValue("@ValorTotal", Convert.ToString(row.Cells["Valor Total"].Value));
                    comando.ExecuteNonQuery();
                }
                conexion.Close();

                string          inserta_totales = "insert into tabla_totales(Subtotal,Impuesto,Descuento,Totalpago) values(" + textBox1.Text + "," + textBox2.Text + "," + textBox3.Text + "," + textBox4.Text + ") ";
                clase_escritura consulta        = new clase_escritura();
                consulta.escribir(database, inserta_totales);

                Vreporte ventanareporte = new Vreporte();
                ventanareporte.Show();
            }

            catch
            {
                //Alerta cuando se quiere generar una factura con campos vacios
                MessageBox.Show("No existen campos para imprimir una factura", "Cesta de compras vacia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
        }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            foreach (DataRow fila in source.Rows)
            {
                string codigo_producto             = fila["Codigo"].ToString();
                string cantidad_productos_vendidos = fila["Cantidad"].ToString();
                //MessageBox.Show(codigo_producto);

                string peticion_stock_actual = "Select Stock from tabla_productos where Codigo=" + codigo_producto + "";

                clase_lectura leer         = new clase_lectura();
                string        stock_actual = leer.leer_un_dato(database, peticion_stock_actual);

                int stock_nuevo = Convert.ToInt32(stock_actual) - Convert.ToInt32(cantidad_productos_vendidos);

                string          peticion_modificar_stock = "update tabla_productos set Stock = " + Convert.ToString(stock_nuevo) + " where Codigo= " + codigo_producto + " ";
                clase_escritura consulta  = new clase_escritura();
                int             resultado = consulta.escribir(database, peticion_modificar_stock);
            }


            SqlConnection conexion = new SqlConnection(database);

            conexion.Open();
            string     inserta_producto_vendidos = "insert into tabla_Ventas(id_factura,Codigo,Detalle,ValorUnitario,Cantidad,ValorTotal) values(@id_factura,@Codigo,@Detalle,@ValorUnitario,@Cantidad,@ValorTotal) ";
            SqlCommand comando           = new SqlCommand(inserta_producto_vendidos, conexion);
            Vproducto  v                 = new Vproducto();
            string     actual_id_factura = textBox5.Text;

            foreach (DataRow fila in source.Rows)
            {
                comando.Parameters.Clear();
                comando.Parameters.AddWithValue("@id_factura", actual_id_factura);
                comando.Parameters.AddWithValue("@Codigo", fila["Codigo"].ToString());
                comando.Parameters.AddWithValue("@Detalle", fila["Detalle"].ToString());
                comando.Parameters.AddWithValue("@ValorUnitario", fila["Valor Unitario"].ToString());
                comando.Parameters.AddWithValue("@Cantidad", fila["Cantidad"].ToString());
                comando.Parameters.AddWithValue("@ValorTotal", fila["Valor Total"].ToString());
                comando.ExecuteNonQuery();
            }
            conexion.Close();


            string          inserta_totales = "insert into tabla_facturas(id_factura,Subtotal,Impuesto,Descuento,Totalpago) values( " + actual_id_factura + " ," + Subtotal + "," + Impuesto + "," + Descuento + "," + Totalpago + ")";
            clase_escritura consulta2       = new clase_escritura();

            consulta2.escribir(database, inserta_totales);

            DialogResult eleccion = MessageBox.Show("Desea Imprimir una factura", "Factura", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

            if (eleccion == DialogResult.Yes)
            {
                SqlConnection conexion3 = new SqlConnection(database);
                conexion3.Open();
                string     inserta_factura = "insert into tabla_factura(Codigo,Detalle,ValorUnitario,Cantidad,ValorTotal) values(@Codigo,@Detalle,@ValorUnitario,@Cantidad,@ValorTotal) ";
                SqlCommand comando3        = new SqlCommand(inserta_factura, conexion3);

                foreach (DataRow fila in source.Rows)
                {
                    comando3.Parameters.Clear();
                    comando3.Parameters.AddWithValue("@Codigo", fila["Codigo"].ToString());
                    comando3.Parameters.AddWithValue("@Detalle", fila["Detalle"].ToString());
                    comando3.Parameters.AddWithValue("@ValorUnitario", fila["Valor Unitario"].ToString());
                    comando3.Parameters.AddWithValue("@Cantidad", fila["Cantidad"].ToString());
                    comando3.Parameters.AddWithValue("@ValorTotal", fila["Valor Total"].ToString());
                    comando3.ExecuteNonQuery();
                }
                conexion.Close();

                string          inserta_totales2 = "insert into tabla_totales(Subtotal,Impuesto,Descuento,Totalpago) values(" + Subtotal + "," + Impuesto + "," + Descuento + "," + Totalpago + ") ";
                clase_escritura consulta         = new clase_escritura();
                consulta.escribir(database, inserta_totales2);

                Vreporte ventanareporte = new Vreporte();
                ventanareporte.Show();
                this.Close();
            }



            else
            {
                this.Close();
            }

            Vproducto ventana = new Vproducto();

            ventana.Hide();
            ventana.Show();
        }
예제 #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            try {
                clase_escritura borrar          = new clase_escritura();
                string          peticion_borrar = "delete from tabla_factura";
                borrar.escribir(database, peticion_borrar);


                int    fila_seleccionada       = dataGridView_facturas.SelectedRows[0].Index;
                string id_factura_seleccionada = dataGridView_facturas.Rows[fila_seleccionada].Cells[0].Value.ToString();
                //MessageBox.Show(id_factura_seleccionada);
                string peticion_lectura = "select Codigo,Detalle,ValorUnitario,Cantidad,ValorTotal from tabla_ventas where Id_factura = '" + Convert.ToString(id_factura_seleccionada) + "' ";


                clase_lectura leer      = new clase_lectura();
                SqlDataReader registros = leer.leer_varios_datos(database, peticion_lectura);
                SqlConnection conexion  = new SqlConnection(database);

                while (registros.Read())
                {
                    string Codigo1        = registros["Codigo"].ToString();
                    string Detalle1       = registros["Detalle"].ToString();
                    string ValorUnitario1 = registros["ValorUnitario"].ToString();
                    string Cantidad1      = registros["Cantidad"].ToString();
                    string ValorTotal1    = registros["ValorTotal"].ToString();

                    string          inserta_factura = "insert into tabla_factura(Codigo,Detalle,ValorUnitario,Cantidad,ValorTotal) values('" + Codigo1 + "','" + Detalle1 + "','" + ValorUnitario1 + "','" + Cantidad1 + "','" + ValorTotal1 + "') ";
                    clase_escritura escritura       = new clase_escritura();
                    int             confirmar       = escritura.escribir(database, inserta_factura);
                }
                registros.Close();
                conexion.Close();

                string        peticion_lectura_totales = "select Subtotal,Impuesto,Descuento,Totalpago from tabla_facturas where Id_factura = '" + Convert.ToString(id_factura_seleccionada) + "' ";
                clase_lectura leer2      = new clase_lectura();
                SqlDataReader registros2 = leer.leer_varios_datos(database, peticion_lectura_totales);
                SqlConnection conexion2  = new SqlConnection(database);

                while (registros2.Read())
                {
                    string Subtotal  = registros2["Subtotal"].ToString();
                    string Impuesto  = registros2["Impuesto"].ToString();
                    string Descuento = registros2["Descuento"].ToString();
                    string Totalpago = registros2["Totalpago"].ToString();

                    string          inserta_totales2 = "insert into tabla_totales(Subtotal,Impuesto,Descuento,Totalpago) values(" + Subtotal + "," + Impuesto + "," + Descuento + "," + Totalpago + ") ";
                    clase_escritura consulta         = new clase_escritura();
                    consulta.escribir(database, inserta_totales2);
                }
                registros2.Close();
                conexion2.Close();

                //Vfacturas_todas ventanareporte = new Vfacturas_todas();
                //ventanareporte.Show();

                Vreporte ventanareporte = new Vreporte();
                ventanareporte.Show();
            }
            catch
            {
                MessageBox.Show("Seleccione toda la fila para visualizar la factura", "Informaciòn", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }