Exemplo n.º 1
0
        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            lblMessage.Text = string.Empty;

            if ((txtHostname.Text != string.Empty && txtDatabase.Text != string.Empty && cbWindowsAuth.IsChecked == true) ||
                (txtHostname.Text != string.Empty && txtDatabase.Text != string.Empty && cbSQLAuth.IsChecked == true && txtApiUsername.Text != string.Empty && txtApiPassword.Text != string.Empty))
            {
                ElexioApi.Connect(txtHostname.Text, txtDatabase.Text, txtApiUsername.Text, txtApiPassword.Text, cbSQLAuth.IsChecked.Value);

                if (ElexioApi.IsConnected)
                {
                    MainWindow mainWindow = new MainWindow();
                    mainWindow.Show();
                    this.Close();
                }
                else
                {
                    lblMessage.Text = $"Could not login with the information provided. {ElexioApi.ErrorMessage}";
                }
            }
            else
            {
                lblMessage.Text = "Please provide the information needed to connect.";
            }
        }
        /// <summary>
        /// Handles the Loaded event of the Window control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // add group types
            ExportGroupTypes = ElexioApi.GetGroupTypes();

            foreach (var groupType in ExportGroupTypes)
            {
                GroupTypesCheckboxItems.Add(new CheckListItem {
                    Id = groupType.Id, Text = groupType.Name, Checked = true
                });
            }

            cblGroupTypes.ItemsSource = GroupTypesCheckboxItems;

            txtImportCutOff.Text = DateTime.Now.ToShortDateString(); // remove before flight (sets today's date as the modified since)
        }
        private void ExportWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            exportWorker.ReportProgress(0, "");

            var exportSettings = ( ExportSettings )e.Argument;

            // clear filesystem directories
            ElexioApi.InitializeExport();

            // export individuals
            if (exportSettings.ExportIndividuals)
            {
                exportWorker.ReportProgress(1, "Exporting Individuals...");
                ElexioApi.ExportIndividuals(exportSettings.ModifiedSince);

                if (ElexioApi.ErrorMessage.IsNotNullOrWhitespace())
                {
                    this.Dispatcher.Invoke(() =>
                    {
                        exportWorker.ReportProgress(2, $"Error exporting individuals: {ElexioApi.ErrorMessage}");
                    });
                }
            }

            // export contributions
            if (exportSettings.ExportContributions)
            {
                exportWorker.ReportProgress(30, "Exporting Financial Accounts...");

                ElexioApi.ExportFinancialAccounts();
                if (ElexioApi.ErrorMessage.IsNotNullOrWhitespace())
                {
                    exportWorker.ReportProgress(31, $"Error exporting financial accounts: {ElexioApi.ErrorMessage}");
                }

                exportWorker.ReportProgress(35, "Exporting Contribution Information...");

                ElexioApi.ExportContributions(exportSettings.ModifiedSince);
                if (ElexioApi.ErrorMessage.IsNotNullOrWhitespace())
                {
                    exportWorker.ReportProgress(36, $"Error exporting financial batches: {ElexioApi.ErrorMessage}");
                }
            }

            // export group types
            if (ExportGroupTypes.Count > 0)
            {
                exportWorker.ReportProgress(54, $"Exporting Groups...");

                ElexioApi.ExportGroups(ExportGroupTypes.Select(t => t.Id).ToList(), exportSettings.ModifiedSince);

                if (ElexioApi.ErrorMessage.IsNotNullOrWhitespace())
                {
                    exportWorker.ReportProgress(54, $"Error exporting groups: {ElexioApi.ErrorMessage}");
                }
            }

            // export attendance
            if (exportSettings.ExportAttendance)
            {
                exportWorker.ReportProgress(75, $"Exporting Attendance...");

                ElexioApi.ExportAttendance(exportSettings.ModifiedSince);

                if (ElexioApi.ErrorMessage.IsNotNullOrWhitespace())
                {
                    exportWorker.ReportProgress(75, $"Error exporting attendance: {ElexioApi.ErrorMessage}");
                }
            }

            // finalize the package
            ImportPackage.FinalizePackage("elexio-export.slingshot");

            // schedule the API status to update (the status takes a few mins to update)
            _apiUpdateTimer.Start();
        }