public MainView() { InitializeComponent(); _setorBLL = new SetorBLL(); _funcionarioBLL = new FuncionarioBLL(); _setores = new List <Setor>(); }
// CHECK SETOR PADRAO //------------------------------------------------------------------------------------------------------------ private bool CheckSetorPadrao(ref objSetor setor) { //--- VERIFICA SETOR string SetorPadrao = ObterDefault("SetorPadrao"); SetorBLL sBLL = new SetorBLL(); if (string.IsNullOrEmpty(SetorPadrao)) { return(false); } else { try { // --- Ampulheta ON Cursor.Current = Cursors.WaitCursor; setor = sBLL.GetSetor(Convert.ToInt32(SetorPadrao)); return(setor != null && setor.IDSetor != null); } catch (Exception ex) { AbrirDialog("Uma exceção ocorreu ao Obter SETOR Padrao..." + "\n" + ex.Message, "Exceção", DialogType.OK, DialogIcon.Exclamation); return(false); } finally { // --- Ampulheta OFF Cursor.Current = Cursors.Default; } } }
private void AtivarDesativar_Setor_Click(object sender, EventArgs e) { //--- verifica se existe alguma cell if (dgvListagem.SelectedRows.Count == 0) { return; } //--- Verifica o item objSetor setor = (objSetor)dgvListagem.SelectedRows[0].DataBoundItem; //--- check saldo existente if (setor.SetorSaldo > 0) { AbrirDialog("Não é possivel desastivar um setor que possui SALDO...", "Saldo Existente", DialogType.OK, DialogIcon.Exclamation); return; } //---pergunta ao usuário var reponse = AbrirDialog($"Deseja realmente {(setor.Ativa ? "DESATIVAR " : "ATIVAR")} esse Setor?\n" + setor.Setor.ToUpper(), (setor.Ativa ? "DESATIVAR " : "ATIVAR"), DialogType.SIM_NAO, DialogIcon.Question); if (reponse == DialogResult.No) { return; } //--- altera o valor setor.Ativa = !setor.Ativa; //--- Salvar o Registro try { // --- Ampulheta ON Cursor.Current = Cursors.WaitCursor; SetorBLL cBLL = new SetorBLL(); cBLL.UpdateSetor(setor); //--- altera a imagem ObterDados(null, null); FiltrarListagem(sender, e); } catch (Exception ex) { AbrirDialog("Uma exceção ocorreu ao Alterar Setor..." + "\n" + ex.Message, "Exceção", DialogType.OK, DialogIcon.Exclamation); } finally { // --- Ampulheta OFF Cursor.Current = Cursors.Default; } }
public void CarregarGrid() { try { IList <SetorDTO> Setor = new List <SetorDTO>(); { Setor = new SetorBLL().CarregarSetor(); dgvVer.AutoGenerateColumns = false; dgvVer.DataSource = Setor; } } catch (Exception erro) { MetroFramework.MetroMessageBox.Show(Owner, "Erro ao tentar carregar os dados!" + erro); } }
// SALVAR REGISTRO //------------------------------------------------------------------------------------------------------------ private void btnSalvar_Click(object sender, EventArgs e) { try { // --- Ampulheta ON Cursor.Current = Cursors.WaitCursor; //--- check data if (!CheckSaveData()) { return; } SetorBLL sBLL = new SetorBLL(); //--- SAVE: INSERT OR UPDATE if (_setor.IDSetor == null) //--- save | Insert { int ID = sBLL.InsertSetor(_setor); //--- define newID _setor.IDSetor = ID; } else //--- update { sBLL.UpdateSetor(_setor); } //--- change Sit Sit = EnumFlagEstado.RegistroSalvo; //--- emit massage AbrirDialog("Registro Salvo com sucesso!", "Registro Salvo", DialogType.OK, DialogIcon.Information); } catch (Exception ex) { AbrirDialog("Uma exceção ocorreu ao Salvar Registro de Setor..." + "\n" + ex.Message, "Exceção", DialogType.OK, DialogIcon.Exclamation); } finally { // --- Ampulheta OFF Cursor.Current = Cursors.Default; } }
// GET DATA //------------------------------------------------------------------------------------------------------------ private void ObterDados(object sender, EventArgs e) { try { // --- Ampulheta ON Cursor.Current = Cursors.WaitCursor; SetorBLL cBLL = new SetorBLL(); listSetor = cBLL.GetListSetor("", true); PreencheListagem(); } catch (Exception ex) { AbrirDialog("Uma exceção ocorreu ao Obter os Dados da listagem..." + "\n" + ex.Message, "Exceção", DialogType.OK, DialogIcon.Exclamation); } finally { // --- Ampulheta OFF Cursor.Current = Cursors.Default; } }
// GET DATA //------------------------------------------------------------------------------------------------------------ private void ObterDados(object sender, EventArgs e) { try { // --- Ampulheta ON Cursor.Current = Cursors.WaitCursor; SetorBLL sBLL = new SetorBLL(); listSetor = sBLL.GetListSetor("", Convert.ToBoolean(cmbAtivo.SelectedValue)); dgvListagem.DataSource = listSetor; } catch (Exception ex) { AbrirDialog("Uma exceção ocorreu ao Obter os Dados da listagem..." + "\n" + ex.Message, "Exceção", DialogType.OK, DialogIcon.Exclamation); } finally { // --- Ampulheta OFF Cursor.Current = Cursors.Default; } }
private void tlSalvar_Click(object sender, RoutedEventArgs e) { try { SetorDTO setordto = new SetorDTO(); SetorBLL setorbll = new SetorBLL(); setordto.Codigo = Convert.ToInt16(txtID.Text); setordto.Nome = txtNomeSetor.Text; setordto.Descricao = txtDescricao.Text; int x = setorbll.alterar(setordto); if (x > 0) { this.ShowMessageAsync("Sucesso!", "Dados salvos com sucesso!"); } } catch (Exception erro) { this.ShowMessageAsync("Erro!", "Erro ao tentar inserir os dados!" + erro); } }
// GET DATA //------------------------------------------------------------------------------------------------------------ private void ObterDadosSetor() { try { // --- Ampulheta ON Cursor.Current = Cursors.WaitCursor; SetorBLL sBLL = new SetorBLL(); listSetor = sBLL.GetListSetor("", null, _congregacao.IDCongregacao); dgvSetor.DataSource = listSetor; FormataListagemSetor(); } catch (Exception ex) { AbrirDialog("Uma exceção ocorreu ao Obter os Dados da listagem..." + "\n" + ex.Message, "Exceção", DialogType.OK, DialogIcon.Exclamation); } finally { // --- Ampulheta OFF Cursor.Current = Cursors.Default; } }
private void txtNome_KeyUp(object sender, KeyEventArgs e) { try { IList <SetorDTO> listar = new List <SetorDTO>(); { SetorDTO setor = new SetorDTO(); setor.Nome = Convert.ToString(txtNome.Text); listar = new SetorBLL().buscar(setor); dgvVer.AutoGenerateColumns = false; dgvVer.DataSource = listar; } if (txtNome.Text == "") { carregarGrid(); } } catch (Exception erro) { MetroFramework.MetroMessageBox.Show(Owner, "Erro ao tentar buscar dados!" + erro); } }
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)); }