private void Pesquisar(string Texto) { if (Convert.ToDateTime(DataInicio) < Convert.ToDateTime(DataFim)) { try { NumberFormatInfo nfi = new CultureInfo("en-US", false).NumberFormat; Lista = VedasDB.GetAllVenda().Where(x => x.DataVendav > Convert.ToDateTime(DataInicio) && x.DataVendav < Convert.ToDateTime(DataFim).AddDays(1)).ToList(); V_Investido = Lista.Select(x => x.PrecoCusto).Sum().ToString(); V_Lucro = Lista.Select(x => x.LucroVenda).Sum().ToString(); V_Margem = (((double.Parse(V_Lucro) * 100) / double.Parse(V_Investido))).ToString("F", nfi); Vendas = Lista; } catch (Exception) { App.Current.MainPage.DisplayAlert("Aviso", " Não há vendas entre essa data ou ocorreu algum erro!", "Ok"); } } else { Vendas = new List <Venda>(); } }
private void OkVenda(object obj) { Item.MetaVenda = double.Parse(ValorVendido); try { double precoCusto = Item.PrecoCompra + Item.ValorInvestido; double lucro = Item.MetaVenda - (Item.PrecoCompra + Item.ValorInvestido); double lucroPecent = (lucro * 100) / (Item.PrecoCompra + Item.ValorInvestido); Venda venda = new Venda() { Nomev = Item.Name, DataComprav = Item.DataCompra, PrecoCusto = precoCusto, DataVendav = DateTime.Now, PrecoComprav = Item.PrecoCompra, PrecoVenda = Item.MetaVenda, LucroVenda = lucro, Lucrov = lucroPecent }; VedasDB.AddVenda(venda, Item); Produtos = ProdutoDB.GetAllProdutos(); } catch (Exception) { } ValorVendido = ""; StackLayout.IsVisible = false; }
private void EntreDatas(string value) { if (Convert.ToDateTime(DataInicio) < Convert.ToDateTime(DataFim)) { try { Lista = VedasDB.GetAllVenda().Where(x => x.DataVendav > Convert.ToDateTime(DataInicio) && x.DataVendav < Convert.ToDateTime(DataFim).AddDays(1)).ToList(); Vendas = Lista; } catch (Exception) { App.Current.MainPage.DisplayAlert("Aviso", " Não há vendas entre essa data ou ocorreu algum erro!", "Ok"); } } }
private async void DeletarProduto(object obj) { try { var resultado = await App.Current.MainPage.DisplayAlert("Aviso", "Tem Certeza Que Deseja Deletar Este Item", "Ok", "Cancelar"); if (resultado == true) { var capital = CapitalGirosDB.GetAllCapitalGiro().FirstOrDefault(); var produt = Produtos.Where(x => x.ProdutoId == Convert.ToInt32(IdProduto)).FirstOrDefault(); capital.Capital = capital.Capital + (produt.PrecoCompra + produt.ValorInvestido); CapitalGirosDB.AddProduto(capital); VedasDB.DeleteVenda(produt); Produtos = ProdutoDB.GetAllProdutos(); } } catch (Exception) { } }
public VendasViewModel() { string Configu = ""; DateTime date = DateTime.Today; GoChatCommand = new Command(GoChat); GoEstoqueCommand = new Command(GoEstoque); PesquisarCommand = new Command <string>(Pesquisar); var mes = date.Month; try { //Configura pagina inicial do app Configu = ConfiguracaoDB.GetAllConfigApp().FirstOrDefault().PaginaInicial; } catch (Exception) { } if (string.IsNullOrEmpty(Configu)) { try { //Lista todas venda realizadas entre uma periodo configurado no banco de dados Lista = VedasDB.GetAllVenda().Where(x => x.DataVendav.Month == mes).ToList(); //Mostra a data na tela DataInicio = new DateTime(date.Year, date.Month, 01); //string.Format("{0}/{1}/{2}", 01, date.Month, date.Year); // new DateTime(date.Year, date.Month, 1).ToString(); int d = DateTime.DaysInMonth(date.Year, date.Month); DataFim = new DateTime(date.Year, date.Month, d); //string.Format("{0}/{1}/{2}", d, date.Month, date.Year); //new DateTime(DateTime.DaysInMonth(date.Year, date.Month), date.Year, date.Month).ToString(); } catch (Exception) { //Evita uma exception em caso de nao haver nada no banco de dados Lista = new List <Venda>() { }; } } else { //Pega a configuração desejada pelo usuario var confg = ConfiguracaoDB.GetAllConfigApp().LastOrDefault(); try { int inicio = 1; int fim = 1; DateTime abreMes; DateTime fechamento; try { inicio = confg.DataFechamento.Day; abreMes = new DateTime(DateTime.Now.Year, DateTime.Now.Month - 1, inicio); } catch (Exception) { inicio = DateTime.DaysInMonth(date.Year, date.Month - 1); abreMes = new DateTime(DateTime.Now.Year, DateTime.Now.Month - 1, inicio); } try { fim = confg.DataFechamento.Day; fechamento = new DateTime(DateTime.Now.Year, DateTime.Now.Month, fim); } catch (Exception) { fim = DateTime.DaysInMonth(date.Year, date.Month); fechamento = new DateTime(DateTime.Now.Year, DateTime.Now.Month, fim); } Lista = VedasDB.GetAllVenda().Where(x => x.DataVendav >= abreMes && x.DataVendav <= fechamento).ToList(); //Mostra a data na tela DataInicio = new DateTime(date.Year, date.Month - 1, inicio); //string.Format("{0}/{1}/{2}", 01, date.Month, date.Year); // new DateTime(date.Year, date.Month, 1).ToString(); //int d = DateTime.DaysInMonth(date.Year, date.Month); DataFim = new DateTime(date.Year, date.Month, fim); //string.Format("{0}/{1}/{2}", d, date.Month, date.Year); //new DateTime(DateTime.DaysInMonth(date.Year, date.Month), date.Year, date.Month).ToString(); } catch (Exception) { if (confg.DataFechamento.Day >= 29 && confg.DataFechamento.Day >= 31) { var fechamento = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); var abreMes = new DateTime(DateTime.Now.Year, DateTime.Now.Month - 1, 1); Lista = VedasDB.GetAllVenda().Where(x => x.DataVendav >= abreMes && x.DataVendav <= fechamento).ToList(); } } } //formata numeros NumberFormatInfo nfi = new CultureInfo("en-US", false).NumberFormat; Vendas = Lista; V_Investido = Lista.Select(x => x.PrecoCusto).Sum().ToString(); V_Lucro = Lista.Select(x => x.LucroVenda).Sum().ToString(); V_Margem = (((double.Parse(V_Lucro) * 100) / double.Parse(V_Investido))).ToString("F", nfi); }