private void BtConsultar_Click(object sender, RoutedEventArgs e)
        {
            //Debemos ver que la fecha de inicio sea antes que la fecha final; de lo contrario mandar un menaje de error
            //CambiosJC
            Boolean res = false;

            if ((cbAnio1.SelectedIndex + 2000) > (cbAnio2.SelectedIndex + 2000))
            {
                MessageBox.Show("Error en los años");
            }
            else
            if ((cbAnio1.SelectedIndex + 2000) == (cbAnio2.SelectedIndex + 2000))
            {
                if ((cbMes1.SelectedIndex + 1) > (cbAnio2.SelectedIndex + 1))
                {
                    MessageBox.Show("Error en los meses");
                }
                else
                if ((cbMes1.SelectedIndex + 1) == (cbMes2.SelectedIndex + 1))
                {
                    if ((cbDia1.SelectedIndex + 1) >= (cbDia2.SelectedIndex + 1))
                    {
                        MessageBox.Show("Error en los días");
                    }
                    else
                    {
                        res = true;
                    }
                }
                else
                {
                    res = true;
                }
            }
            else
            {
                res = true;
            }

            //Comprobación de la fecha
            if (res)
            {
                String fechaIni, fechaFin;
                fechaIni = "" + (cbAnio1.SelectedIndex + 2000) + "-" + (cbMes1.SelectedIndex + 1) + "-" + (cbDia1.SelectedIndex + 1) + " 00:00:00.000";
                fechaFin = "" + (cbAnio2.SelectedIndex + 2000) + "-" + (cbMes2.SelectedIndex + 1) + "-" + (cbDia2.SelectedIndex + 1) + " 23:59:59.000";
                try
                {
                    SqlConnection con = Conexion.conectar();
                    SqlCommand    cmd = new SqlCommand(String.Format("select pedidosProductos.idPedido, pedidosProductos.idProducto, pedidos.fechaHora, pedidosProductos.cantidad*productos.costo as Ganancia from productos," +
                                                                     " pedidosProductos, pedidos where productos.idProducto = pedidosProductos.idProducto and pedidosProductos.idPedido = pedidos.idPedido and fechaHora between '{0}' and '{1}'", fechaIni, fechaFin), con);
                    SqlDataReader rd;
                    rd = cmd.ExecuteReader();
                    int          total = 0;
                    List <Venta> lis   = new List <Venta>();
                    int          i     = 1;
                    while (rd.Read())
                    {
                        Venta ven;
                        ven          = new Venta();
                        ven.numPed   = rd.GetInt32(0);
                        ven.numProd  = rd.GetInt32(1);
                        ven.fechaPed = rd.GetDateTime(2);
                        ven.ganancia = rd.GetInt32(3);
                        total        = total + ven.ganancia;
                        lis.Add(ven);
                        i++;
                    }
                    dgVentas.ItemsSource = lis;
                    txTotal.Text         = "$ " + total;
                    rd.Close();
                    con.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message);
                }
            }
            else
            {
                MessageBox.Show("Las fechas están mal");
            }
        }
Example #2
0
        private void BtContinuar_Click(object sender, RoutedEventArgs e)
        {
            int idEm;

            try
            {
                idEm = int.Parse(tbUsuario.Text);
                int res = Conexion.comprobarEmpleo(idEm);
                if (res > 0)
                {
                    if (Conexion.comprabarPwd(idEm, pbContra.Password))
                    {
                        SqlConnection con;
                        SqlDataReader rd;
                        con = Conexion.conectar();
                        SqlCommand cmd = new SqlCommand(String.Format("select puesto from empleados where idEmpleado= {0} and contrasenia = '{1}'", idEm, pbContra.Password), con);
                        rd = cmd.ExecuteReader();
                        App.Current.Properties["idUsuarioActivo"] = tbUsuario.Text;
                        if (rd.Read())
                        {
                            if (rd.GetString(0).Equals("Empleado"))
                            {
                                App.Current.Properties["usuarioActivo"] = "Empleado";
                                Empleado w = new Empleado();
                                w.Show();
                                this.Close();
                            }
                            else
                            {
                                if (rd.GetString(0).Equals("Gerente"))
                                {
                                    App.Current.Properties["usuarioActivo"] = "Gerente";
                                    Gerente w = new Gerente();
                                    w.Show();
                                    this.Close();
                                }
                                else
                                {
                                    if (rd.GetString(0).Equals("Dueño"))
                                    {
                                        App.Current.Properties["usuarioActivo"] = "Dueño";
                                        Dueño w = new Dueño();
                                        w.Show();
                                        this.Close();
                                    }
                                }
                            }
                        }
                        con.Close();
                        rd.Close();
                    }
                    else
                    {
                        MessageBox.Show("contraseña incorrecta");
                    }
                }
                else
                {
                    if (res < 0)
                    {
                        MessageBox.Show("El empleado no existe");
                    }
                    else
                    {
                        MessageBox.Show("El empleado ya no trabaja aquí");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error");
            }
        }