Пример #1
0
        private void buttonSalvar_Click(object sender, RoutedEventArgs e)
        {
            string id = textBoxID.Text;
            string cliente = textBoxCliente.Text;
            string produto = textBoxProduto.Text;
            string detalhes = textBoxDetalhes.Text;
            DateTime? cadastro = dateCadastro.Value;

            if(string.IsNullOrWhiteSpace(cliente))
            {
                MessageBox.Show("Cliente obrigatório");
                return;
            }

            if (string.IsNullOrWhiteSpace(produto))
            {
                MessageBox.Show("Cliente obrigatório");
                return;
            }

            using (var context = new DBPropostasContext(App.connectionString))
            {
                if(!string.IsNullOrWhiteSpace(id))
                {
                    Proposta proposta = context.Proposta.First(p => p.ID.ToString() == id);
                    proposta.Cliente = cliente;
                    proposta.DescProduto = produto;
                    proposta.Detalhes = detalhes;
                    proposta.DataCadastro = (DateTime)cadastro;
                    context.SubmitChanges();
                }
                else
                {
                    Proposta proposta = new Proposta()
                    {
                        Cliente = cliente,
                        DescProduto = produto,
                        Detalhes = detalhes,
                        DataCadastro = (DateTime)cadastro
                    };
                    context.Proposta.InsertOnSubmit(proposta);
                    context.SubmitChanges();
                }
            }

            NavigationService.GoBack();

        }
Пример #2
0
        /// <summary>
        /// Constructor for the Application object.
        /// </summary>
        public App()
        {
            // Global handler for uncaught exceptions.
            UnhandledException += Application_UnhandledException;

            // Standard XAML initialization
            InitializeComponent();

            // Phone-specific initialization
            InitializePhoneApplication();

            // Language display initialization
            InitializeLanguage();

            // Show graphics profiling information while debugging.
            if (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;

                // Prevent the screen from turning off while under the debugger by disabling
                // the application's idle detection.
                // 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 _context = new DBPropostasContext(App.connectionString))
            {
                if (!_context.DatabaseExists()) _context.CreateDatabase();
            }

        }
 private void buttonRemover_Click(object sender, EventArgs e)
 {
     if (listPropostas.SelectedItems.Count == 0)
     {
         MessageBox.Show("Selecione uma proposta para remover");
         return;
     }
     if(MessageBox.Show("Deseja remover a proposta selecionada?", "Remoção", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
     {
         Proposta proposta = (Proposta)listPropostas.SelectedItem;
         using(var context = new DBPropostasContext(App.connectionString))
         {
             context.Proposta.Attach(proposta);
             context.Proposta.DeleteOnSubmit(proposta);
             context.SubmitChanges();
             FiltrarPropostas();
         }
     }
 }