Пример #1
0
        public static List <AnswersCollection> BuildGroupedByQuestion(int teamStart, int teamEnd, int RoundsCount, int QuestionsPerRound, string headerTemplate)
        {
            var result = new List <AnswersCollection>();

            for (int roundId = 1; roundId <= RoundsCount; roundId++)
            {
                for (int queryId = 1; queryId <= QuestionsPerRound; queryId++)
                {
                    var resultItem = new AnswersCollection();
                    resultItem.Headers = new Queue <QuestionForm>(RoundsCount * QuestionsPerRound);
                    for (int teamId = teamStart; teamId <= teamEnd; teamId++)
                    {
                        resultItem.Headers.Enqueue(new QuestionForm()
                        {
                            QuestionId         = queryId,
                            RoundId            = roundId,
                            TeamId             = teamId,
                            EndToEndQuestionId = (roundId - 1) * QuestionsPerRound + queryId,
                            HeaderTemplate     = headerTemplate
                        });
                    }
                    result.Add(resultItem);
                }
            }
            return(result);
        }
Пример #2
0
        public static AnswersCollection BuildGroupedByTeam(int teamId, int RoundsCount, int QuestionsPerRound, string headerTemplate)
        {
            AnswersCollection result = new AnswersCollection();

            result.Headers = new Queue <QuestionForm>(RoundsCount * QuestionsPerRound);
            for (int roundId = 1; roundId <= RoundsCount; roundId++)
            {
                for (int queryId = 1; queryId <= QuestionsPerRound; queryId++)
                {
                    result.Headers.Enqueue(new QuestionForm()
                    {
                        QuestionId         = queryId,
                        RoundId            = roundId,
                        TeamId             = teamId,
                        EndToEndQuestionId = (roundId - 1) * QuestionsPerRound + queryId,
                        HeaderTemplate     = headerTemplate
                    });
                }
            }
            return(result);
        }
Пример #3
0
        public static List <AnswersCollection> BuildGroupedByTeamForCutter(int teamStart, int teamEnd, int RoundsCount, int QuestionsPerRound, string headerTemplate,
                                                                           int cellsOnXAxis, int cellsOnYAxis)
        {
            var result = new List <AnswersCollection>();

            for (int roundId = 1; roundId <= RoundsCount; roundId++)
            {
                var teamsCount = teamEnd - teamStart + 1;

                for (int teamId = teamStart; teamId <= teamEnd; teamId += cellsOnYAxis)
                {
                    for (int queryId = 1; queryId <= (QuestionsPerRound + cellsOnXAxis - 1) / cellsOnXAxis; queryId += 1)
                    {
                        var resultItem = new AnswersCollection();
                        resultItem.Headers = new Queue <QuestionForm>(RoundsCount * QuestionsPerRound); // ?

                        for (int row = 0; row < cellsOnYAxis; row += 1)
                        {
                            for (int col = 0; col < cellsOnXAxis; col += 1)
                            {
                                resultItem.Headers.Enqueue(new QuestionForm()
                                {
                                    QuestionId         = queryId + col * cellsOnYAxis,
                                    RoundId            = roundId,
                                    TeamId             = teamId + row,
                                    EndToEndQuestionId = (roundId - 1) * QuestionsPerRound + queryId + col * cellsOnYAxis,
                                    HeaderTemplate     = headerTemplate
                                });
                            }
                        }

                        result.Add(resultItem);
                    }
                }
            }

            return(result);
        }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the TournamentViewModel class.
        /// </summary>
        public TournamentViewModel()
        {
            PrinterSettings.InstalledPrinters.Cast <string>();
            _RoundsCount           = 3;
            _QuestionsPerRound     = 12;
            OpenSpreadsheetCommand = new GalaSoft.MvvmLight.Command.RelayCommand(() =>
            {
                try
                {
                    var dlg             = new SaveFileDialog();
                    dlg.FileName        = "tournament.ods";
                    dlg.AddExtension    = true;
                    dlg.DefaultExt      = "*.ods";
                    dlg.CheckFileExists = false;
                    dlg.Filter          = "OpenOffice Calc Spreadsheet|*.ods";
                    if (dlg.ShowDialog().Value)
                    {
                        var fileData = Properties.Resources.tournamentFinal;
                        var path     = dlg.FileName;
                        File.WriteAllBytes(path, fileData);
                    }
                }
                catch (Exception ex)
                {
                    ShowError("Не удалось сохранить файл. " + ex.ToString());
                }
            });
            PrintCommand = new GalaSoft.MvvmLight.Command.RelayCommand(() =>
            {
                IsProcessing = true;
                ThreadPool.QueueUserWorkItem(new WaitCallback((o) =>
                {
                    try
                    {
                        QuestionForms = new List <AnswersCollection>();

                        if (GroupByQuestion)
                        {
                            QuestionForms =
                                AnswersCollection.BuildGroupedByQuestion(TeamsRangeBegin, TeamsRangeEnd, RoundsCount, QuestionsPerRound, ItemHeaderTemplate);
                        }
                        else
                        {
                            var width  = UseSize_4x9 ? 4 : 3;
                            var height = UseSize_4x9 ? 9 : 5;

                            if (GroupForCutter)
                            {
                                QuestionForms =
                                    AnswersCollection.BuildGroupedByTeamForCutter(TeamsRangeBegin, TeamsRangeEnd, RoundsCount, QuestionsPerRound, ItemHeaderTemplate,
                                                                                  width, height);
                            }
                            else
                            {
                                for (int teamId = TeamsRangeBegin; teamId <= TeamsRangeEnd; teamId++)
                                {
                                    QuestionForms.Add(
                                        AnswersCollection.BuildGroupedByTeam(teamId, RoundsCount, QuestionsPerRound, ItemHeaderTemplate));
                                }
                            }
                        }


                        using (var printDocument1 = new System.Drawing.Printing.PrintDocument())
                        {
                            printDocument1.PrinterSettings.PrinterName = TargetPrinter;
                            printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument1_PrintPage);
                            printDocument1.Print();
                        }
                        IsProcessing = false;
                    }
                    catch (Exception ex)
                    {
                        ShowError("Не удалось напечатать документ. " + ex.ToString());
                    }
                }));
            }, () => !IsProcessing);
            if (IsInDesignMode)
            {
                // Code runs in Blend --> create design time data.
            }
            else
            {
                // Code runs "for real"
            }
        }