예제 #1
0
    protected void Import(object sender, WizardNavigationEventArgs e)
    {
        CSVImporter csvimporter = CurrentImporter;

        if (e == null)
        {
            throw new ArgumentNullException("e");
        }

        if (csvimporter == null || csvimporter.HasErrors)
        {
            lblError.Text = Resources.LogbookEntry.ImportNotSuccessful;
            e.Cancel      = true;
            SetWizardStep(wsPreview);
            PreviewData();  // rebuild the table.
            return;
        }

        csvimporter.FCommit((le, fIsNew) => {
            if (String.IsNullOrEmpty(le.ErrorString))
            {
                AddTextRow(plcProgress, String.Format(CultureInfo.CurrentCulture, fIsNew ? Resources.LogbookEntry.ImportRowAdded : Resources.LogbookEntry.ImportRowUpdated, le.ToString()), "success");
            }
            else
            {
                AddTextRow(plcProgress, String.Format(CultureInfo.CurrentCulture, Resources.LogbookEntry.ImportRowNotAdded, le.ToString(), le.ErrorString), "error");
            }
        },
                            (le, ex) => {
            AddTextRow(plcProgress, String.Format(CultureInfo.CurrentCulture, Resources.LogbookEntry.ImportRowNotAdded, le.ToString(), ex.Message), "error");
        });
        MyFlightbook.Profile.GetUser(Page.User.Identity.Name).SetAchievementStatus(MyFlightbook.Achievements.Achievement.ComputeStatus.NeedsComputing);
        mvPreviewResults.SetActiveView(vwImportResults);
        wzImportFlights.Visible     = false;
        pnlImportSuccessful.Visible = true;
        CurrentImporter             = null;
        CurrentCSVSource            = null;
    }
예제 #2
0
    protected void Import(object sender, WizardNavigationEventArgs e)
    {
        CSVImporter csvimporter = CurrentImporter;

        if (e == null)
        {
            throw new ArgumentNullException("e");
        }

        if (csvimporter == null)
        {
            lblError.Text = Resources.LogbookEntry.ImportNotSuccessful;
            e.Cancel      = true;
            SetWizardStep(wsPreview);
            PreviewData();  // rebuild the table.
            return;
        }

        int cFlightsAdded      = 0;
        int cFlightsUpdated    = 0;
        int cFlightsWithErrors = 0;

        csvimporter.FCommit((le, fIsNew) =>
        {
            if (String.IsNullOrEmpty(le.ErrorString))
            {
                AddTextRow(plcProgress, String.Format(CultureInfo.CurrentCulture, fIsNew ? Resources.LogbookEntry.ImportRowAdded : Resources.LogbookEntry.ImportRowUpdated, le.ToString()), "success");
                if (fIsNew)
                {
                    cFlightsAdded++;
                }
                else
                {
                    cFlightsUpdated++;
                }
            }
            else
            {
                PendingFlight pf = new PendingFlight(le)
                {
                    User = User.Identity.Name
                };
                pf.Commit();
                lnkPending.Visible = true;
                AddTextRow(plcProgress, String.Format(CultureInfo.CurrentCulture, Resources.LogbookEntry.ImportRowAddedPending, le.ToString(), le.ErrorString), "error");
                cFlightsWithErrors++;
            }
        },
                            (le, ex) =>
        {
            AddTextRow(plcProgress, String.Format(CultureInfo.CurrentCulture, Resources.LogbookEntry.ImportRowNotAdded, le.ToString(), ex.Message), "error");
        },
                            true);

        List <string> lstResults = new List <string>();

        if (cFlightsAdded > 0)
        {
            lstResults.Add(String.Format(CultureInfo.CurrentCulture, Resources.LogbookEntry.ImportFlightsAdded, cFlightsAdded));
        }
        if (cFlightsUpdated > 0)
        {
            lstResults.Add(String.Format(CultureInfo.CurrentCulture, Resources.LogbookEntry.ImportFlightsUpdated, cFlightsUpdated));
        }
        if (cFlightsWithErrors > 0)
        {
            lstResults.Add(String.Format(CultureInfo.CurrentCulture, Resources.LogbookEntry.ImportFlightsWithErrors, cFlightsWithErrors));
        }
        rptImportResults.DataSource = lstResults;
        rptImportResults.DataBind();
        MyFlightbook.Profile.GetUser(Page.User.Identity.Name).SetAchievementStatus(MyFlightbook.Achievements.Achievement.ComputeStatus.NeedsComputing);
        mvPreviewResults.SetActiveView(vwImportResults);
        wzImportFlights.Visible     = false;
        pnlImportSuccessful.Visible = true;
        CurrentImporter             = null;
        CurrentCSVSource            = null;
    }