Пример #1
0
        protected void PreviewData()
        {
            lblError.Text = string.Empty;

            mvPreviewResults.SetActiveView(vwPreviewResults);                                // default to showing results.

            mfbImportAircraft1.CandidatesForImport = Array.Empty <AircraftImportMatchRow>(); // start fresh every time.

            byte[] rgb = CurrentCSVSource;
            if (rgb == null || rgb.Length == 0)
            {
                lblFileRequired.Text = Resources.LogbookEntry.errImportInvalidCSVFile;
                SetWizardStep(wsUpload);
                return;
            }

            int cOriginalSize = rgb.Length;

            pnlConverted.Visible = pnlAudit.Visible = false;

            ExternalFormatConvertResults results = ExternalFormatConvertResults.ConvertToCSV(rgb);

            lblAudit.Text       = results.AuditResult;
            hdnAuditState.Value = results.ResultString;
            CurrentCSVSource    = results.GetConvertedBytes();

            int cConvertedSize = CurrentCSVSource.Length;

            IsPendingOnly = IsPendingOnly || results.IsPendingOnly; // results can change between first preview and import, so if it's true anywhere along the way, preserve that.

            if (!String.IsNullOrEmpty(results.ConvertedName))
            {
                lblFileWasConverted.Text = String.Format(CultureInfo.CurrentCulture, Resources.LogbookEntry.importLabelFileWasConverted, results.ConvertedName);
                pnlConverted.Visible     = true;
            }

            pnlAudit.Visible = (results.IsFixedOrBroken);
            if (results.IsBroken)
            {
                lblAudit.CssClass = "error";
                ExpandoAudit.ExpandoControl.Collapsed   = false;
                ExpandoAudit.ExpandoControl.ClientState = "false";
            }
            else
            {
                lblAudit.CssClass = string.Empty;
                ExpandoAudit.ExpandoControl.Collapsed   = true;
                ExpandoAudit.ExpandoControl.ClientState = "true";
            }

            pnlAudit.Visible = pnlConverted.Visible || !String.IsNullOrEmpty(lblAudit.Text);

            ErrorContext.Clear();
            CSVImporter csvimporter = CurrentImporter = new CSVImporter(mfbImportAircraft1.ModelMapping);

            csvimporter.InitWithBytes(CurrentCSVSource, User.Identity.Name, AddSuccessRow, AddErrorRow, ckAutofill.Checked);

            if (csvimporter.FlightsToImport == null || !String.IsNullOrEmpty(csvimporter.ErrorMessage))
            {
                lblFileRequired.Text = csvimporter.ErrorMessage;
                SetWizardStep(wsUpload);
                return;
            }

            rptPreview.DataSource = csvimporter.FlightsToImport;
            rptPreview.DataBind();
            mvPreview.SetActiveView(csvimporter.FlightsToImport.Count > 0 ? vwPreview : vwNoResults);

            if (wzImportFlights.ActiveStep == wsMissingAircraft)
            {
                EventRecorder.LogCall("Import Preview - User: {user}, Upload size {cbin}, converted size {cbconvert}, flights found: {flightcount}", User.Identity.Name, cOriginalSize, cConvertedSize, csvimporter.FlightsToImport.Count);
            }

            mvMissingAircraft.SetActiveView(vwNoMissingAircraft); // default state.

            if (csvimporter.FlightsToImport.Count > 0)
            {
                if (csvimporter.HasErrors)
                {
                    if (!IsPendingOnly)
                    {
                        lblError.Text = Resources.LogbookEntry.ImportPreviewNotSuccessful;
                    }

                    List <AircraftImportMatchRow> missing = new List <AircraftImportMatchRow>(csvimporter.MissingAircraft);
                    if (missing.Count > 0)
                    {
                        mfbImportAircraft1.CandidatesForImport = missing;
                        mvMissingAircraft.SetActiveView(vwAddMissingAircraft);
                    }

                    ((Button)wzImportFlights.FindControl("FinishNavigationTemplateContainerID$btnNewFile")).Visible = true;
                }

                ((AjaxControlToolkit.ConfirmButtonExtender)wzImportFlights.FindControl("FinishNavigationTemplateContainerID$confirmImportWithErrors")).Enabled = csvimporter.HasErrors;
            }
        }