public static string GetUserName()
        {
            try
            {
                string retorno;
                string data = Get("BudgShopTicket");
                if (data == null)
                {
                    return(null);
                }
                string[] dados = data.Split(',');
                if (dados[1] == "1")
                {
                    SupermercadoBLL bll          = new SupermercadoBLL();
                    Supermercado    supermercado = bll.selecionaSupermercado(Convert.ToInt32(dados[0]));
                    retorno = supermercado.Nome;
                }
                else
                {
                    UsuarioBLL bll     = new UsuarioBLL();
                    Usuario    usuario = bll.selecionarPorID(Convert.ToInt32(dados[0]));
                    retorno = usuario.Nome;
                }

                return(retorno);
            }
            catch (Exception)
            {
                return(null);
            }
        }
        public ActionResult Index()
        {
            SupermercadoBLL     supermercado = new SupermercadoBLL();
            List <Supermercado> lista        = supermercado.selecionaTodosSupermercado();

            return(View(lista));
        }
        public ActionResult ContaParceiro(HttpPostedFileBase uploadFile, Supermercado supermercado, string xmlsetor, string arraybyte, string setores, string Produtosetores, string NomeDoSetor,
                                          string ProdutoNome, string ProdutoPreco, string ProdutoQuantidade, string ProdutoPeso, string ProdutoImagem, string ProdutoPromocao, string ProdutoDataDeInicio, string ProdutoDataDeTermino)
        {
            SqlWhereSetor where = new SqlWhereSetor();
            SetorDAL        dal             = new SetorDAL();
            SupermercadoBLL supermercadoBLL = new SupermercadoBLL();

            string[] array = WebApp.Models.Cookie.Get("BudgShopTicket").Split(',');
            supermercado.ID = Convert.ToInt32(array[0]);

            //Se Post é para importação do xml
            try
            {
                if (!string.IsNullOrWhiteSpace(uploadFile.FileName))
                {
                    try
                    {
                        var xmlPath = Server.MapPath("~/Content" + uploadFile.FileName);
                        uploadFile.SaveAs(xmlPath);
                        XSDProduto xsd    = new XSDProduto();
                        Boolean    valido = xsd.validaXML(xmlPath);
                        if (valido)
                        {
                            Setor setorxsd = new Setor();
                            setorxsd.CodigoMercado = supermercado.ID;
                            setorxsd.Nome          = xmlsetor;
                            XDocument      rootNode = XDocument.Load(xmlPath);
                            List <Produto> nodes    = rootNode.Descendants("Produto").
                                                      Select(p => new Produto
                            {
                                Nome          = p.Element("Nome").Value,
                                Preco         = Convert.ToDouble(p.Element("Preco").Value),
                                Quantidade    = Convert.ToInt32(p.Element("Quantidade").Value),
                                Peso          = Convert.ToDouble(p.Element("Peso").Value),
                                Imagem        = p.Element("Imagem").Value,
                                Promocao      = Convert.ToDouble(p.Element("Promocao").Value),
                                importancia   = 0,
                                Acessos       = 0,
                                DataDeInicio  = Convert.ToDateTime(p.Element("DataDeInicio").Value),
                                DataDeTermino = Convert.ToDateTime(p.Element("DataDeTermino").Value)
                            }).ToList();
                            setorxsd.Produto = nodes;
                            dal.InsertXML(setorxsd);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            catch (Exception)
            {
            }

            //Se Post é para inserir produto
            if (!string.IsNullOrWhiteSpace(ProdutoNome) && !string.IsNullOrWhiteSpace(ProdutoPreco))
            {
                try
                {
                    List <Produto> listaparainserir = new List <Produto>();
                    Produto        produto          = new Produto();
                    produto.Nome          = ProdutoNome;
                    produto.Preco         = Convert.ToDouble(ProdutoPreco);
                    produto.Quantidade    = Convert.ToInt32(ProdutoQuantidade);
                    produto.Peso          = Convert.ToDouble(ProdutoPeso);
                    produto.Imagem        = ProdutoImagem;
                    produto.Promocao      = Convert.ToDouble(ProdutoPromocao);
                    produto.DataDeInicio  = Convert.ToDateTime(ProdutoDataDeInicio);
                    produto.DataDeTermino = Convert.ToDateTime(ProdutoDataDeTermino);
                    produto.Acessos       = 0;
                    produto.importancia   = 0;
                    SqlCommand     command = where.XmlCodAndSetor(supermercado.ID, Produtosetores);
                    List <Produto> prod    = dal.SelectXML(command);
                    try
                    {
                        if (prod.Count > 0)
                        {
                            listaparainserir.AddRange(prod);
                        }
                    }
                    catch (Exception)
                    {
                    }
                    try
                    {
                        listaparainserir.Add(produto);
                    }
                    catch (Exception)
                    {
                    }
                    Setor setorxml = new Setor();
                    setorxml.CodigoMercado = supermercado.ID;
                    setorxml.Nome          = Produtosetores;
                    setorxml.Produto       = listaparainserir;
                    setorxml.ID            = 0;
                    SqlCommand comando = new SqlCommand();
                    dal.DeleteXMLRow(setorxml, comando);
                    dal.InsertXML(setorxml);
                }
                catch (Exception)
                {
                    ViewBag.ErroInsertProduto = "Erro no cadastro";
                }


                try
                {
                    supermercado.Logo = arraybyte.Split(',')[1];
                }
                catch (Exception)
                {
                }
            }
            //Se post for para atualizar o supermercado
            if (string.IsNullOrWhiteSpace(supermercado.CNPJ))
            {
                ViewBag.message = supermercadoBLL.atualizaSupermercado(supermercado);
            }
            //Se post for para inserir setor
            if (!string.IsNullOrWhiteSpace(NomeDoSetor))
            {
                List <Produto> listavazia = new List <Produto>();
                Setor          setor      = new Setor();
                setor.Nome          = NomeDoSetor;
                setor.CodigoMercado = supermercado.ID;
                setor.Produto       = listavazia;
                try
                {
                    dal.InsertXML(setor);
                }
                catch (Exception)
                {
                    ViewBag.InsertSetor = "Erro no cadastro";
                }
            }
            List <Produto> produtos = new List <Produto>();

            try
            {
                SqlCommand    comando      = where.XmlCod(supermercado.ID);
                List <string> listasetores = dal.SelectSetores(comando);
                SqlCommand    command      = where.XmlCodAndSetor(supermercado.ID, setores);
                produtos        = dal.SelectXML(command);
                ViewBag.setores = listasetores;
            }
            catch (Exception)
            {
            }
            if (!string.IsNullOrWhiteSpace(setores))
            {
                SqlCommand cmd = where.XmlCodAndSetor(supermercado.ID, setores);
                produtos = dal.SelectXML(cmd);
            }
            ViewBag.SetorSelecionado = setores;
            return(View(produtos));
        }
Exemple #4
0
        public ActionResult Registrar(Supermercado supermercado, string NomeUser, string SobrenomeUser,
                                      string EmailUser, string LocalizacaoUser, string SenhaUser, string arraybyte)
        {
            try
            {
                supermercado.Logo = arraybyte.Split(',')[1];
            }
            catch (Exception)
            {
            }

            string login;
            string senha;
            //Base64Converter base64 = new Base64Converter();
            Usuario user = new Usuario();

            //byte[] array = (byte[])conversor.ConvertTo(file, typeof(byte[]));
            //MemoryStream memstr = new MemoryStream(array);
            //System.Drawing.Image img = System.Drawing.Image.FromStream(memstr);
            //base64.ImageToBase64();
            user.Nome        = NomeUser;
            user.Sobrenome   = SobrenomeUser;
            user.Email       = EmailUser;
            user.Senha       = SenhaUser;
            user.Localizacao = LocalizacaoUser;
            UsuarioBLL usuarioBLL = new UsuarioBLL();

            ViewBag.Message1 = usuarioBLL.inseriUsuario(user);

            SupermercadoBLL supermercadoBLL = new SupermercadoBLL();

            ViewBag.Message2 = supermercadoBLL.inseriSupermercado(supermercado);

            LoginBLL loginbll = new LoginBLL();

            if (string.IsNullOrEmpty(user.Email))
            {
                login = supermercado.CNPJ;
                senha = supermercado.Senha;
                Login(login, senha);
            }
            else
            {
                login = user.Email;
                senha = user.Senha;
                Login(login, senha);
            }
            //dynamic objeto = loginbll.verificaLogin(login, senha);
            //if (objeto.GetType() == typeof(Supermercado))
            //{
            //    Cookie.Set("BudgShopTicket", objeto.ID.ToString() + "," + "1");
            //    return RedirectToAction("Index", "Home");
            //}
            //else
            //{
            //    Cookie.Set("BudgShopTicket", objeto.ID.ToString() + "," + "2");
            //    return RedirectToAction("Index", "Home");
            //}

            return(View());
        }
Exemple #5
0
        public ActionResult Comparar(string listaFinal, string localizacao)
        {
            string endereco = "";

            while (string.IsNullOrWhiteSpace(endereco))
            {
                try
                {
                    string  url            = "https://maps.googleapis.com/maps/api/geocode/json?key=AIzaSyA-sAUEFZVEDmzTx4DYXxwoEusdL7IsGSc&latlng=" + localizacao.Split(',')[0] + "," + localizacao.Split(',')[1] + "&sensor=false";
                    JObject jsonEndereco   = getJsonByUrl(url);
                    JArray  jarrayEndereco = (JArray)jsonEndereco.SelectToken("results");
                    endereco = (string)jarrayEndereco[0].SelectToken("formatted_address");
                }
                catch
                {
                }
            }
            string                   json            = Server.UrlDecode(listaFinal);
            RootObject               root            = JsonConvert.DeserializeObject <RootObject>(json);
            List <Item>              itens           = root.value.items;
            SupermercadoBLL          bll             = new SupermercadoBLL();
            List <Supermercado>      supermercados   = bll.selecionaTodosSupermercado();
            List <MercadoViewModels> lista           = new List <MercadoViewModels>();
            GoogleLocationService    locationSvc     = new GoogleLocationService("AIzaSyA-sAUEFZVEDmzTx4DYXxwoEusdL7IsGSc");
            AddressData              enderecoCliente = new AddressData();

            enderecoCliente.Address = endereco;

            foreach (Supermercado supermercado in supermercados)
            {
                MercadoViewModels Mercado      = new MercadoViewModels();
                double            Preco        = 0;
                List <Item>       itensMercado = new List <Item>();
                foreach (Item item in itens)
                {
                    Item itemMercado = new Item();
                    itemMercado.amount = SetorBLL.TrazPreco(item, supermercado.ID);
                    if (itemMercado.amount != 0)
                    {
                        itemMercado = item;
                        Preco      += itemMercado.amount * itemMercado.quantity;
                        itensMercado.Add(itemMercado);
                    }
                }
                Mercado.Itens = itensMercado;
                Mercado.ItensNaoEncontrados = itens.Except(Mercado.Itens).ToList();
                Mercado.PrecoFinal          = Preco;
                Mercado.SuperMercado        = supermercado;
                lista.Add(Mercado);
                AddressData enderecoMercado = new AddressData();
                enderecoMercado.Address = supermercado.Endereco;
                Directions directions = new Directions();
                while (directions.Distance == null)
                {
                    try
                    {
                        directions = locationSvc.GetDirections(enderecoCliente, enderecoMercado);
                    }
                    catch (Exception)
                    {
                    }
                }
                Mercado.Proximidade = Convert.ToDouble(directions.Distance.Split(' ')[0], new CultureInfo("en-us"));
            }
            ComparadorMercadosViewModels Comparador = new ComparadorMercadosViewModels();

            Comparador.OutrosMercados       = lista;
            Comparador.MercadosMenorPreco   = lista.FindAll(o => o.ItensNaoEncontrados.Count() == 0).ToList().OrderBy(o => o.PrecoFinal).Take(3).ToList();
            Comparador.OutrosMercados       = Comparador.OutrosMercados.Except(Comparador.MercadosMenorPreco).ToList();
            Comparador.MercadosMaisProximos = lista.FindAll(o => o.ItensNaoEncontrados.Count() == 0).ToList().OrderBy(o => o.Proximidade).Take(3).ToList();
            Comparador.OutrosMercados       = Comparador.OutrosMercados.Except(Comparador.MercadosMaisProximos).ToList();
            try
            {
                Comparador.MercadoNossaSugestao = (MercadoViewModels)lista.FindAll(o => o.ItensNaoEncontrados.Count() == 0).ToList().OrderBy(o => (o.Proximidade * 0.3 + o.PrecoFinal * 0.7)).ToArray()[0];
            }
            catch { }
            Comparador.OutrosMercados.Remove(Comparador.MercadoNossaSugestao);

            return(View(Comparador));
        }