public IList<TB_BENEFICIARIO> GetBeneficiaries()
        {
            IList<TB_BENEFICIARIO> list = null;
            using (var ctx = new ControleDeGastosDataContext(App.Connection))
            {
                IQueryable<TB_BENEFICIARIO> query = ctx.TB_BENEFICIARIOs;

                list = query.ToList();
            }
            return list;
        }
        public IList<TB_ORCAMENTO> GetBudgets()
        {
            IList<TB_ORCAMENTO> list = null;
            using (var ctx = new ControleDeGastosDataContext(App.Connection))
            {
                IQueryable<TB_ORCAMENTO> query = ctx.TB_ORCAMENTOs;

                list = query.ToList();
            }
            return list;
        }
        /*
        public IList<TB_TIPO_CONTA> GetAccountType()
        {
            IList<TB_TIPO_CONTA> list = null;
            using (var ctx = new ControleDeGastosDataContext(App.Connection))
            {
                IQueryable<TB_TIPO_CONTA> query = ctx.TB_TIPO_CONTAS;

                list = query.ToList();
            }
            return list;
        }
        */
        public IList<TB_CATEGORIA> GetCategories()
        {
            IList<TB_CATEGORIA> list = null;
            using (var ctx = new ControleDeGastosDataContext(App.Connection))
            {
                IQueryable<TB_CATEGORIA> query = ctx.TB_CATEGORIAs;

                list = query.ToList();
            }
            return list;
        }
        public IList<TB_MOEDA> GetCurrencys()
        {
            IList<TB_MOEDA> list = null;
            using (var ctx = new ControleDeGastosDataContext(App.Connection))
            {
                IQueryable<TB_MOEDA> query = ctx.TB_MOEDAs;

                list = query.ToList();
            }
            return list;
        }
        public IList<TB_CONTA> GetAccount()
        {
            IList<TB_CONTA> list = null;
            using (var ctx = new ControleDeGastosDataContext(App.Connection))
            {
                IQueryable<TB_CONTA> query = ctx.TB_CONTAS;

                list = query.ToList();
            }
            return list;
        }
        /// <summary>
        /// Constructor for the Application object.
        /// </summary>
        public App()
        {
            // Global handler for uncaught exceptions. 
            UnhandledException += Application_UnhandledException;

            // Standard Silverlight initialization
            InitializeComponent();

            // Phone-specific initialization
            InitializePhoneApplication();

            // Show graphics profiling information while debugging.
            if (System.Diagnostics.Debugger.IsAttached)
            {
                // Display the current frame rate counters
                Application.Current.Host.Settings.EnableFrameRateCounter = true;

                // Show the areas of the app that are being redrawn in each frame.
                //Application.Current.Host.Settings.EnableRedrawRegions = true;

                // Enable non-production analysis visualization mode, 
                // which shows areas of a page that are handed off to GPU with a colored overlay.
                //Application.Current.Host.Settings.EnableCacheVisualization = true;

                // Disable the application idle detection by setting the UserIdleDetectionMode property of the
                // application's PhoneApplicationService object to Disabled.
                // Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run
                // and consume battery power when the user is not using the phone.
                PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
            }

            using (var ctx = new ControleDeGastosDataContext(connection))
            {
                if (!ctx.DatabaseExists())
                {
                    ctx.CreateDatabase();
                    SampleData();
                }

            };

        }
        public void SampleData()
        {
            string connection = App.Connection;
            using (var ctx = new ControleDeGastosDataContext(App.Connection))
            {
                TB_TIPO_CONTA novoTipoConta = new TB_TIPO_CONTA()
                {
                    TPC_NOME = "Banco",
                    TPC_FLAG_ATIVA = true
                };
                ctx.TB_TIPO_CONTAs.InsertOnSubmit(novoTipoConta);

                novoTipoConta = new TB_TIPO_CONTA()
                {
                    TPC_NOME = "Investimento",
                    TPC_FLAG_ATIVA = true
                };
                ctx.TB_TIPO_CONTAs.InsertOnSubmit(novoTipoConta);

                novoTipoConta = new TB_TIPO_CONTA()
                {
                    TPC_NOME = "Dinheiro",
                    TPC_FLAG_ATIVA = true
                };
                ctx.TB_TIPO_CONTAs.InsertOnSubmit(novoTipoConta);

                ctx.SubmitChanges();

                TB_MOEDA novaMoeda = new TB_MOEDA()
                {
                    MOE_NOME = "Real Brasil",
                    MOE_SIGLA = "R$",
                    MOE_COTACAO = 0,
                    MOE_PADRAO = true,
                    MOE_FLAG_ATIVA = true
                };
                ctx.TB_MOEDAs.InsertOnSubmit(novaMoeda);

                novaMoeda = new TB_MOEDA()
                {
                    MOE_NOME = "Dólar",
                    MOE_SIGLA = "$",
                    MOE_COTACAO = 0,
                    MOE_PADRAO = false,
                    MOE_FLAG_ATIVA = true
                };
                ctx.TB_MOEDAs.InsertOnSubmit(novaMoeda);

                ctx.SubmitChanges();

                TB_BENEFICIARIO novoBeneficiario = new TB_BENEFICIARIO()
                {
                    BNF_NOME = "Wagner Sommer",
                    BNF_OBSERVACAO = "Pai",
                    BNF_FLAG_ATIVA = true
                };
                ctx.TB_BENEFICIARIOs.InsertOnSubmit(novoBeneficiario);

                novoBeneficiario = new TB_BENEFICIARIO()
                {
                    BNF_NOME = "Margarete Sommer",
                    BNF_OBSERVACAO = "Mãe",
                    BNF_FLAG_ATIVA = true
                };
                ctx.TB_BENEFICIARIOs.InsertOnSubmit(novoBeneficiario);

                ctx.SubmitChanges();

                TB_CONTA novaConta = new TB_CONTA()
                {
                    CTA_NOME = "Pessoa Fisica",
                    TPC_ID = 1,
                    CTA_DT_INICIO = System.DateTime.Today,
                    CTA_DT_FIM = Convert.ToDateTime(System.DateTime.MaxValue.ToString()),
                    CTA_VALOR_INICIAL = 0,
                    MOE_ID = 1,
                    CTA_ENCERRADA = false,
                    CTA_FLAG_ATIVA = true
                };
                ctx.TB_CONTAS.InsertOnSubmit(novaConta);

                novaConta = new TB_CONTA()
                {
                    CTA_NOME = "Pessoa Juridica",
                    TPC_ID = 1,
                    CTA_DT_INICIO = System.DateTime.Today,
                    CTA_DT_FIM = Convert.ToDateTime(System.DateTime.MaxValue.ToString()),
                    CTA_VALOR_INICIAL = 0,
                    MOE_ID = 1,
                    CTA_ENCERRADA = false,
                    CTA_FLAG_ATIVA = true
                };
                ctx.TB_CONTAS.InsertOnSubmit(novaConta);

                novaConta = new TB_CONTA()
                {
                    CTA_NOME = "Acoes",
                    TPC_ID = 2,
                    CTA_DT_INICIO = System.DateTime.Today,
                    CTA_DT_FIM = Convert.ToDateTime(System.DateTime.MaxValue.ToString()),
                    CTA_VALOR_INICIAL = 0,
                    MOE_ID = 1,
                    CTA_ENCERRADA = false,
                    CTA_FLAG_ATIVA = true
                };
                ctx.TB_CONTAS.InsertOnSubmit(novaConta);

                ctx.SubmitChanges();

                TB_CATEGORIA novaCategoria = new TB_CATEGORIA()
                {
                    CAT_NOME = "Automovel",
                    CAT_PAI_ID = 1,
                    CAT_TIPO = "1",
                    CAT_FLAG_ATIVA = true,
                    CAT_OBSERVACAO = ""
                };
                ctx.TB_CATEGORIAs.InsertOnSubmit(novaCategoria);

                ctx.SubmitChanges();

                TB_ORCAMENTO novoOrcamento = new TB_ORCAMENTO()
                {
                    ORC_NOME = "Carro",
                    ORC_TIPO = 1,
                    MOE_ID = 1,
                    CAT_ID = 1,
                    ORC_VALOR = 100,
                    ORC_FLAG_ATIVA = true,
                    ORC_OBSERVACAO = "Mensal",
                    ORC_SUBCATEGORIA = false
                };
                ctx.TB_ORCAMENTOs.InsertOnSubmit(novoOrcamento);

                novoOrcamento = new TB_ORCAMENTO()
                {
                    ORC_NOME = "Casa",
                    ORC_TIPO = 2,
                    MOE_ID = 1,
                    CAT_ID = 1,
                    ORC_VALOR = 500,
                    ORC_FLAG_ATIVA = true,
                    ORC_OBSERVACAO = "Trimestral",
                    ORC_SUBCATEGORIA = false
                };
                ctx.TB_ORCAMENTOs.InsertOnSubmit(novoOrcamento);

                ctx.SubmitChanges();


            }
        }
        public IList<TB_MOVIMENTACAO> GetTransaction()
        {
            IList<TB_MOVIMENTACAO> list = null;
            using (var ctx = new ControleDeGastosDataContext(App.Connection))
            {
                IQueryable<TB_MOVIMENTACAO> query = ctx.TB_MOVIMENTACAOs;

                list = query.ToList();
            }
            return list;
        }
 public void deleteAccount(TB_CONTA account)
 {
     using (var ctx = new ControleDeGastosDataContext(App.Connection))
     {
         // find a city to delete
         IQueryable<TB_CONTA> accountQuery = from c in ctx.TB_CONTAS where c.CTA_NOME == account.CTA_NOME select c;
         TB_CONTA accountToDelete = accountQuery.FirstOrDefault();
         // delete city from the context
         ctx.TB_CONTAS.DeleteOnSubmit(accountToDelete);
         // save changes to the database
         ctx.SubmitChanges();
     }
 }