Ejemplo n.º 1
0
        private void btn_Buscar_Click_1(object sender, EventArgs e)
        {
            factura = false;
            validar1();
            if (factura)
            {
                string Mensaje = con.BuscarDev(mtb_Factura.Text.ToString());
                int    Dias    = 0;

                if (Mensaje == "Existe")
                {
                    validar();
                    if (letra2)
                    {
                        nud_Cantidad.Enabled = true;
                        try
                        {
                            con.cmd = new SqlCommand("select DATEDIFF(DAY, fecha_Venta, GETDATE()) Dias " +
                                                     "from Ventas where num_factura = '" + mtb_Factura.Text.ToString() + "'", con.sc);
                            con.AbrirConexion();
                            SqlDataReader read = con.cmd.ExecuteReader();
                            if (read.Read())
                            {
                                Dias = int.Parse(read["Dias"].ToString());
                            }
                            con.CerrarConexion();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("ERROR " + ex);
                        }

                        if (Dias < 3)
                        {
                            dgvCambio.Enabled   = true;
                            btn_Buscar.Visible  = false;
                            mtb_Factura.Enabled = false;
                            /////////////
                            string query = "SELECT cod_prducto Producto, CONCAT(p.nombre, ' ', p.marca, ' ', p.color) Descripción, cantidad [Cantidad Vendida], vd.precioVenta Precio " +
                                           "FROM Ventas v inner join VentaDetalle vd on v.num_factura = vd.num_factura inner join Productos p on vd.cod_prducto = p.cod_producto " +
                                           "where v.num_factura = '" + mtb_Factura.Text.ToString() + "'";
                            tabla.CargarDatosTablas(dgvCambio, query);
                        }
                        else
                        {
                            MessageBox.Show("La fecha de venta excedio la fecha limite de devolucion.", "Limite excedido", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Error, no se encontro la factura", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        private void btn_AgregarProd_Click(object sender, EventArgs e)
        {
            string nMensaje;

            con.cmd = new SqlCommand("if exists(SELECT cod_producto FROM Productos where cod_producto = '" + txtcodigoproducto.Text.ToString() + "') begin SELECT 'Existe' Mensaje end", con.sc);
            con.AbrirConexion();
            SqlDataReader read = con.cmd.ExecuteReader();

            if (read.Read())
            {
                nMensaje = read["Mensaje"].ToString();
            }
            else
            {
                nMensaje = "No existe";
            }
            con.CerrarConexion();

            if (nMensaje == "Existe")
            {
                numero2 = false; letra1 = false;
                validar();
                if (numero2 && letra1)
                {
                    datosTablas.AgregarDatos(txtcodigoproducto.Text.ToString(), int.Parse(txtcantidad.Text.ToString()));
                    dgvventas.Rows.Add(datos.Codigo, datos.Descripcion, datos.Precio, datos.Cantidad.ToString(), (datos.Precio * datos.Cantidad).ToString());
                    datos.Subtotal = 0;
                    foreach (DataGridViewRow row in dgvventas.Rows)
                    {
                        double precio    = (double)row.Cells["columna_precio"].Value;
                        int    cantidad  = int.Parse(row.Cells["columna_cantidad"].Value.ToString());
                        double totalUnit = precio * cantidad;
                        datos.Subtotal += totalUnit;
                    }

                    datos.CalculoDescuento();
                    datos.CalculoImpuesto();
                    datos.CalculoTotal();
                    txtSubtotal.Text       = datos.Subtotal.ToString();
                    txtDescuento.Text      = datos.Descuento.ToString();
                    txtImpuesto.Text       = datos.Impuesto.ToString();
                    txttotal.Text          = datos.Total.ToString();
                    txtcodigoproducto.Text = "";
                    txtcantidad.Text       = "";
                }
                else
                {
                    MessageBox.Show("ERROR");
                }
            }
            else
            {
                MessageBox.Show("" + nMensaje + " el producto en inventario.", "Producto Inexistente", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnEliminar_Click(object sender, EventArgs e)
        {
            try
            {
                int    indice = dgvEgreso.CurrentCell.RowIndex;
                string codigo = dgvEgreso.Rows[indice].Cells["Codigo"].Value.ToString();

                conex.cmd = new SqlCommand("DELETE FROM Empleados WHERE cod_empleado = '" + codigo + "'", conex.sc);

                conex.AbrirConexion();
                conex.cmd.ExecuteNonQuery();
                conex.CerrarConexion();
            }
            catch (Exception ex)
            {
                MessageBox.Show("ERROR " + ex);
            }
            tabla.CargarDatosTablas(dgvEgreso, query);
        }
 private void bnt_Buscar_Click(object sender, EventArgs e)
 {
     con.da = new SqlDataAdapter("WITH ReporteFinanciero AS (SELECT " +
                                 "[Mes]						= MONTH(fecha_Venta),"+
                                 "[Ventas Brutas]			= SUM(vd.precioVenta * vd.cantidad), "+
                                 "[Ventas Brutas Mes Pasado]	= LAG(SUM(vd.precioVenta * vd.cantidad)) OVER (ORDER BY MONTH(fecha_Venta)) " +
                                 "FROM Ventas v inner join VentaDetalle vd on v.num_factura = vd.num_factura " +
                                 "where fecha_Venta between '" + dtpFecha1.Value.ToShortDateString() + "' and '" + dtpFecha2.Value.ToShortDateString() + "' " +
                                 "GROUP BY MONTH(fecha_Venta)) " +
                                 "SELECT [Mes],[Ventas Brutas],[Ventas Brutas Mes Pasado],[Crecimiento Mensual] = 100.0 * ([Ventas Brutas] - [Ventas Brutas Mes Pasado])/ [Ventas Brutas Mes Pasado]FROM [ReporteFinanciero] " +
                                 "ORDER BY [Mes]", con.sc);
     try
     {
         con.AbrirConexion();
         con.dt = new DataTable();
         con.da.Fill(con.dt);
         dgvReporteFinanciero.DataSource = con.dt;
         con.CerrarConexion();
     }
     catch (Exception ex)
     {
         MessageBox.Show("ERROR: " + ex);
     }
 }
        private void btnAgregar_Click(object sender, EventArgs e)
        {
            con.cmd = new SqlCommand("if exists(Select cod_usuario from Usuarios where cod_usuario = '" + txt_Usuario.Text.ToString() + "') begin Select 'Existe' Mensaje end", con.sc);
            con.AbrirConexion();
            SqlDataReader lector = con.cmd.ExecuteReader();

            if (lector.Read())
            {
                con.CerrarConexion();
                MessageBox.Show("Ya existe el usuario.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txt_Usuario.Focus();
                txt_Usuario.Text = "";
            }
            else
            {
                con.CerrarConexion();
                letra1 = false; letra2 = false; letra3 = false; letra4 = false; letra5 = false; numero2 = false;
                validar();
                if (letra1 && letra2 && letra3 && letra4 && letra5 && numero2)
                {
                    if (cb_Genero.SelectedIndex != -1 && cb_Puesto.SelectedIndex != -1)
                    {
                        int    indiceGen = cb_Genero.SelectedIndex + 1;
                        int    indicePos = cb_Puesto.SelectedIndex + 1;
                        string codEmp    = txtNombre.Text.Substring(0, 3) + txtApellidos.Text.Substring(0, 3);
                        double salario   = 0.00;

                        switch (indicePos)
                        {
                        case 1:
                            salario = 18500.00;
                            break;

                        case 2:
                            salario = 15350.00;
                            break;

                        case 3:
                            salario = 12600.00;
                            break;

                        default:
                            salario = 0.00;
                            break;
                        }

                        con.cmd = new SqlCommand("INSERT INTO Usuarios(cod_usuario, contraseña, confirmacion) " +
                                                 "values('" + txt_Usuario.Text.ToString() + "', '" + txt_Contrasena.Text.ToString() + "', '" + txt_Confirmacion.Text.ToString() + "')", con.sc);
                        try
                        {
                            con.AbrirConexion();
                            con.cmd.ExecuteNonQuery();
                            con.CerrarConexion();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("ERROR " + ex);
                        }

                        if (String.IsNullOrEmpty(txtCorreo.Text))
                        {
                            con.cmd = new SqlCommand("INSERT INTO Empleados(cod_empleado, nombres, apellidos, cod_puesto, cod_usuario, " +
                                                     "salario, fecha_contratacion, fecha_nacimiento, cod_genero, telefono) " +
                                                     "values('" + codEmp + "','" + txtNombre.Text.ToString() + "','" + txtApellidos.Text.ToString() + "','" + indicePos + "'," +
                                                     "'" + txt_Usuario.Text.ToString() + "','" + salario + "',GETDATE(),'" + dtp_FechaNAc.Value.ToString("yyy/MM/dd") + "','" + indiceGen + "'," +
                                                     "'" + mtxttelefono.Text.ToString() + "')", con.sc);
                        }
                        else
                        {
                            con.cmd = new SqlCommand("INSERT INTO Empleados(cod_empleado, nombres, apellidos, cod_puesto, cod_usuario, " +
                                                     "salario, fecha_contratacion, fecha_nacimiento, cod_genero, correo, telefono) " +
                                                     "values('" + codEmp + "', '" + txtNombre.Text.ToString() + "', '" + txtApellidos.Text.ToString() + "', '" + indicePos + "', " +
                                                     "'" + txt_Usuario.Text.ToString() + "', '" + salario + "', GETDATE(), '" + dtp_FechaNAc.Value.ToString("yyy/MM/dd") + "', '" + indiceGen + "', " +
                                                     "'" + txtCorreo.Text.ToString() + "', '" + mtxttelefono.Text.ToString() + "')", con.sc);
                        }

                        try
                        {
                            con.AbrirConexion();
                            con.cmd.ExecuteNonQuery();
                            con.CerrarConexion();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("ERROR " + ex);
                        }

                        txtNombre.Text          = "";
                        txtApellidos.Text       = "";
                        txtCorreo.Text          = "";
                        txt_Confirmacion.Text   = "";
                        txt_Contrasena.Text     = "";
                        txt_Usuario.Text        = "";
                        mtxttelefono.Text       = "";
                        cb_Genero.SelectedIndex = -1;
                        cb_Puesto.SelectedIndex = -1;
                    }
                    else
                    {
                        if (cb_Genero.SelectedIndex != -1)
                        {
                            ErrorProvider.SetError(cb_Puesto, "Seleccione una opcion.");
                        }
                        if (cb_Puesto.SelectedIndex != -1)
                        {
                            ErrorProvider.SetError(cb_Genero, "Seleccione una opcion.");
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public void Insertar()
        {
            //Codigo proveedor
            con.sql = string.Format("select cod_proveedor from Proveedores pr where nombre = '" + cb_ProveedoresPRB.SelectedItem.ToString() + "'");
            con.cmd = new SqlCommand(con.sql, con.sc);
            try
            {
                con.AbrirConexion();
                SqlDataReader lector = con.cmd.ExecuteReader();
                if (lector.Read())
                {
                    proveedor = lector["cod_proveedor"].ToString();
                }
                con.CerrarConexion();
            }
            catch (Exception ex)
            {
                MessageBox.Show("ERROR " + ex);
            }
            //INSERT a tabla de compras y detalles

            //Verificar Compra
            con.cmd = new SqlCommand("if exists(SELECT cod_compra FROM Compras where cod_compra = '" + txtFacturaCompra.Text.ToString() + "') begin Select 'Existe' Mensaje End", con.sc);

            con.AbrirConexion();
            SqlDataReader rd = con.cmd.ExecuteReader();

            if (rd.Read())
            {
                string mensaje = rd["Mensaje"].ToString();
                con.CerrarConexion();
            }
            else
            {
                con.CerrarConexion();
                //Compra
                con.cmd = new SqlCommand("INSERT INTO Compras(cod_compra, fecha_compra, descuentoPorcentaje, impuestoPorcentaje, cod_empleado, cod_proveedor) " +
                                         "values('" + txtFacturaCompra.Text.ToString() + "','" + dtp_Compra.Value.ToShortDateString() + "','0.00'," +
                                         "'0.15','" + con.Cod_empleado + "','" + proveedor + "')", con.sc);
                try
                {
                    con.AbrirConexion();
                    con.CerrarConexion();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("ERROR: " + ex);
                }
            }

            //Detalle
            con.cmd = new SqlCommand("INSERT INTO CompraDetalle(cod_compra,cod_producto, cantidad, precioCompra) " +
                                     "values('" + txtFacturaCompra.Text.ToString() + "','" + txtcodigoproducto.Text.ToString() + "','" + txtcantidad.Text.ToString() + "','" + txtprecio.Text.ToString() + "')", con.sc);
            try
            {
                con.AbrirConexion();
                con.cmd.ExecuteNonQuery();
                con.CerrarConexion();
            }
            catch (Exception ex)
            {
                MessageBox.Show("ERROR: " + ex);
            }
        }