Ejemplo n.º 1
0
        public List<customer> GetCustomersByCriteria(customer criteria)
        {
            List<customer> customers = GetCustomers();

            if (!string.IsNullOrEmpty(criteria.nome)) {
                customers = customers.Where(c => c.nome.ToUpper().Contains(criteria.nome.ToUpper())).ToList<customer>();
            }

            if (criteria.sexo > 0)
            {
                customers = customers.Where(c => c.sexo.Equals(criteria.sexo)).ToList<customer>();
            }

            if (criteria.id_cidade > 0) {
                customers = customers.Where(c => c.id_cidade.Equals(criteria.id_cidade)).ToList<customer>();
                if (criteria.id_regiao > 0) {
                    customers = customers.Where(c => c.id_regiao.Equals(criteria.id_regiao)).ToList<customer>();
                }
            }

            if (criteria.fromLastPurchase != DateTime.MinValue) {
                customers = customers.Where(c => c.ultima_compra >= criteria.fromLastPurchase).ToList<customer>();
            }

            if (criteria.toLastPurchase != DateTime.MinValue)
            {
                customers = customers.Where(c => c.ultima_compra <= criteria.toLastPurchase).ToList<customer>();
            }

            if (criteria.id_classificacao > 0) {
                customers = customers.Where(c=>c.id_classificacao.Equals(criteria.id_classificacao)).ToList<customer>();
            }

            if (criteria.id_usuario > 0) {
                customers = customers.Where(c => c.id_usuario.Equals(criteria.id_usuario)).ToList<customer>();
            }

            foreach (var item in customers)
            {
                item.classificacaoNome = new classificacaoBLL().GetClassificationById(item.id_classificacao).nome;
                item.usuarioNome = new usuarioBLL().GetUserById(item.id_usuario).nome;
                item.cidadeNome = new cidadeBLL().GetCityById(item.id_cidade).nome;
                item.regiaoNome = new regiaoBLL().GetRegionById(item.id_regiao).nome;
            }

            // Filter the list
            return customers;
        }
Ejemplo n.º 2
0
        // Search
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            // Set up the customer object that will serve as criteria for the search
            customer criteria = new customer();

            criteria.nome = txtName.Text.Trim();
            criteria.sexo = Convert.ToInt32(ddlGender.SelectedValue);
            criteria.id_cidade = Convert.ToInt32(ddlCity.SelectedValue);
            criteria.id_regiao = Convert.ToInt32(ddlRegion.SelectedValue);
            DateTime fromDate = DateTime.MinValue;
            DateTime.TryParse(txtFromDate.Text, out fromDate);
            criteria.fromLastPurchase = fromDate;
            DateTime toDate = DateTime.MinValue;
            DateTime.TryParse(txtToDate.Text, out toDate);
            criteria.toLastPurchase = toDate;
            criteria.id_classificacao = Convert.ToInt32(ddlClassification.SelectedValue);
            if (ddlSeller != null && ddlSeller.Items.Count > 0) {
                criteria.id_usuario = Convert.ToInt32(ddlSeller.SelectedValue);
            }
            else
            {
                criteria.id_usuario = Convert.ToInt32(Session["loggedin"].ToString());
            }
            List<customer> list;
            using(customerBLL bll = new customerBLL())
            {
                 list = bll.GetCustomersByCriteria(criteria);
            }

            grdContacts.AutoGenerateColumns = false;
            grdContacts.DataSource = list;
            grdContacts.DataBind();

            if (!UserIsAdmin())
            {
                grdContacts.Columns[7].Visible = false;
            }

            ViewState["dtSource"] = list;
        }