Пример #1
0
        private void button8_Click(object sender, EventArgs e)
        {
            button4.Enabled = true;
            factura  fact  = new factura();
            DateTime fecha = DateTime.Now;

            fact.agregarFactura(Convert.ToInt32(textBox1.Text), Convert.ToInt32(textBox4.Text), fecha);

            Conexion      cnn = new Conexion();
            SqlConnection cn  = new SqlConnection(cnn.LeerConexion());
            SqlCommand    cmd = new SqlCommand("UltimoFactura", cn);

            cmd.CommandType = CommandType.StoredProcedure;


            try
            {
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable      tb = new DataTable();
                da.Fill(tb);
                textBox10.Text = tb.Rows[0][0].ToString();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally{
                cn.Dispose();
                cmd.Dispose();
            }
        }
Пример #2
0
        private void button4_Click(object sender, EventArgs e)
        {
            factura fact = new factura();

            fact.agregarProducto(Convert.ToInt32(textBox10.Text), Convert.ToInt32(textBox12.Text));
            fact.cantidad(Convert.ToInt32(textBox12.Text), Convert.ToInt32(textBox7.Text));
            MostrarGrid();
            sumarTotal();
        }
Пример #3
0
        private void button6_Click(object sender, EventArgs e)
        {
            Reporte report = new Reporte();

            report.ShowDialog();
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                string idProducto, cantidad, existencia;
                int    nuevaCantidad;
                cantidad   = dataGridView1.Rows[i].Cells[5].Value.ToString();
                idProducto = dataGridView1.Rows[i].Cells[0].Value.ToString();

                Conexion      cnn = new Conexion();
                SqlConnection cn  = new SqlConnection(cnn.LeerConexion());
                SqlCommand    cmd = new SqlCommand("MostrarPorIDProducto", cn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@idProducto", dataGridView1.Rows[i].Cells[0].Value);

                try
                {
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    DataTable      tb = new DataTable();
                    da.Fill(tb);
                    existencia = tb.Rows[0][4].ToString();
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
                finally
                {
                    cn.Dispose();
                    cmd.Dispose();
                }

                nuevaCantidad = Convert.ToInt32(existencia) - Convert.ToInt32(cantidad);
                factura fact = new factura();
                fact.modificarStock(Convert.ToInt32(idProducto), nuevaCantidad);
            }
            MessageBox.Show("La orden fue enviada, puede imprimir recibo");
        }
Пример #4
0
        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            string idproducto, existencia;
            int    cantidad;
            double costo, precio;

            try
            {
                cantidad = int.Parse(dataGridView1.CurrentRow.Cells[5].Value.ToString());
                if (Convert.ToInt32(cantidad) < 0 || Convert.ToInt32(cantidad) == 0)
                {
                    MessageBox.Show("Solo puede ingresar numeros positivos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    Conexion      cnn = new Conexion();
                    SqlConnection cn  = new SqlConnection(cnn.LeerConexion());
                    SqlCommand    cmd = new SqlCommand("MostrarPorIDProducto", cn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@idProducto", dataGridView1.CurrentRow.Cells[0].Value);
                    try
                    {
                        SqlDataAdapter da2 = new SqlDataAdapter(cmd);
                        DataTable      tb2 = new DataTable();
                        da2.Fill(tb2);
                        string variable = tb2.Rows[0][5].ToString();
                        existencia = tb2.Rows[0][4].ToString();
                        precio     = double.Parse(variable);
                        cantidad   = int.Parse(dataGridView1.CurrentRow.Cells[5].Value.ToString());
                        costo      = precio * cantidad;
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                    finally
                    {
                        cn.Dispose();
                        cmd.Dispose();
                    }

                    if (Convert.ToInt32(cantidad) <= Convert.ToInt32(existencia))
                    {
                        if (Convert.ToInt32(cantidad) <= Convert.ToInt32(existencia))
                        {
                            idproducto = dataGridView1.CurrentRow.Cells[0].Value.ToString();
                            factura fac = new factura();
                            fac.modificarCompra(Convert.ToInt32(idproducto), Convert.ToInt32(cantidad), Convert.ToDouble(costo));
                            MostrarGrid();
                            sumarTotal();
                        }
                        else
                        {
                            MessageBox.Show("La cantidad supera el stock disponible", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        MessageBox.Show("La cantidad supera el stock disponible", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("El valor no puede ser nulo");
            }
        }