Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PrintOptionsDialog"/> class.
        /// </summary>
        /// <param name="pto">The pto.</param>
        /// <param name="doc">The document.</param>
        /// <exception cref="System.ArgumentNullException">pto or doc</exception>
        public PrintOptionsDialog(PlanExportSettings pto, PrintDocument doc)
        {
            pto.ThrowIfNull(nameof(pto));

            doc.ThrowIfNull(nameof(doc));

            InitializeComponent();

            string curPrinter = doc.PrinterSettings.PrinterName;

            m_pto = pto;

            foreach (String printer in PrinterSettings.InstalledPrinters)
            {
                int index = comboPrinters.Items.Add(printer);

                doc.PrinterSettings.PrinterName = printer;
                if (doc.PrinterSettings.IsDefaultPrinter)
                    comboPrinters.SelectedIndex = index;
            }

            // If this dialog is cancelled, we dont want the name of the printer to have changed
            doc.PrinterSettings.PrinterName = curPrinter;

            EntryFinishDate = pto.EntryFinishDate;
            EntryNumber = pto.EntryNumber;
            EntryStartDate = pto.EntryStartDate;
            EntryTrainingTimes = pto.EntryTrainingTimes;
            EntryNotes = pto.EntryNotes;
            FooterCount = pto.FooterCount;
            FooterDate = pto.FooterDate;
            FooterTotalTime = pto.FooterTotalTime;
            IncludeHeader = pto.IncludeHeader;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Exports the plan under a text format.
        /// </summary>
        /// <param name="planToExport">The plan to export.</param>
        /// <param name="settings">The settings.</param>
        /// <param name="exportActions">The export actions.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">
        /// planToExport
        /// or
        /// settings
        /// </exception>
        /// <exception cref="System.NotImplementedException"></exception>
        /// <exception cref="System.ArgumentNullException">planToExport or settings</exception>
        public static string ExportAsText(Plan planToExport, PlanExportSettings settings,
            Action<StringBuilder, PlanEntry, PlanExportSettings> exportActions = null)
        {
            planToExport.ThrowIfNull(nameof(planToExport));

            settings.ThrowIfNull(nameof(settings));

            PlanScratchpad plan = new PlanScratchpad(planToExport.Character, planToExport);
            plan.Sort(planToExport.SortingPreferences);
            plan.UpdateStatistics();

            StringBuilder builder = new StringBuilder();
            Character character = (Character)plan.Character;

            // Initialize constants
            string lineFeed = Environment.NewLine;
            string boldStart = String.Empty;
            string boldEnd = String.Empty;

            switch (settings.Markup)
            {
                case MarkupType.Forum:
                    boldStart = "[b]";
                    boldEnd = "[/b]";
                    break;
                case MarkupType.Html:
                    lineFeed = $"<br />{Environment.NewLine}";
                    boldStart = "<b>";
                    boldEnd = "</b>";
                    break;
                case MarkupType.Undefined:
                case MarkupType.None:
                    break;
                default:
                    throw new NotImplementedException();
            }

            // Header
            if (settings.IncludeHeader)
            {
                builder.Append(boldStart)
                    .Append($"{(settings.ShoppingList ? "Shopping list " : "Skill plan ")} for {character.Name}")
                    .Append(boldEnd)
                    .Append(lineFeed)
                    .Append(lineFeed);
            }

            // Scroll through entries
            int index = 0;
            DateTime endTime = DateTime.Now;
            foreach (PlanEntry entry in plan)
            {
                // Skip is we're only build a shopping list
                bool shoppingListCandidate = !(entry.CharacterSkill.IsKnown || entry.Level != 1 || entry.CharacterSkill.IsOwned);
                if (settings.ShoppingList && !shoppingListCandidate)
                    continue;

                // Remapping point
                if (!settings.ShoppingList && (entry.Remapping != null) && settings.RemappingPoints)
                {
                    builder
                        .Append($"***{entry.Remapping}***")
                        .Append(lineFeed);
                }

                // Entry's index
                index++;
                if (settings.EntryNumber)
                    builder.Append($"{index}. ");

                // Name
                builder.Append(boldStart);
                AddName(settings, entry, builder);
                builder.Append(boldEnd);

                // Training time
                AddTrainingTime(settings, shoppingListCandidate, entry, builder);

                exportActions?.Invoke(builder, entry, settings);

                builder.Append(lineFeed);

                // End time
                endTime = entry.EndTime;
            }

            // Footer
            AddFooter(settings, boldEnd, index, endTime, builder, lineFeed, plan, boldStart);

            // Returns the text representation.
            return builder.ToString().TrimEnd(Environment.NewLine.ToCharArray());
        }