示例#1
0
        public void Parse()
        {
            string word      = "";
            bool   isComment = false;
            int    i         = 0;

            while (i < CodeBlock.Length)
            {
                if ('#' == CodeBlock[i])
                {
                    isComment = true;
                    Runs.Add(new Run()
                    {
                        Text = CodeBlock[i].ToString(), Foreground = new SolidColorBrush(Color.FromArgb(255, 50, 255, 0))
                    });
                }
                else if (" \n\t.:;()[]{}-+*/".Contains(CodeBlock[i]))
                {
                    Runs.Add(new Run()
                    {
                        Text = CodeBlock[i].ToString()
                    });
                    if (CodeBlock[i] == '\n')
                    {
                        isComment = false;
                    }
                }
            }
        }
示例#2
0
 public void AssignTo(WorkerRegistration registration)
 {
     Requires.NotNull(registration, "registration");
     Runs.Add(new RunAttempt(registration));
     AssignedToWorker = registration;
     SetStatus(WorkItemStatus.InProgress);
 }
示例#3
0
        private void Algorithm_Stopped(object sender, EventArgs e)
        {
            var cloner          = new Cloner();
            var algRun          = cloner.Clone(Algorithm.Runs.Last());
            var clonedSnapshots = cloner.Clone(snapshots);

            algRun.Results.Add("TimeLimitRunSnapshots", clonedSnapshots);
            Runs.Add(algRun);
            Algorithm.Runs.Clear();
            OnStopped();
        }
示例#4
0
 public void Run()
 {
     Runs.Add(RunNumber);
     Runner(this);
     if (Failed)
     {
         HandleFailure();
         return;
     }
     RunNumber++;
 }
示例#5
0
        public void Add(T value)
        {
            var last = Runs.Count - 1;

            // See if we can add it to the last run
            if (Runs.Count > 0 && Runs[last].Length != byte.MaxValue && Runs[last].Value.Equals(value))
            {
                Runs[last] = new Run((byte)(Runs[last].Length + 1), Runs[last].Value);
            }
            else
            {
                // Else add new 1 element run
                Runs.Add(new Run(0, value));
            }
        }
        private TextRun _GetTextRun(int textSourceCharacterIndex)
        {
            _charIndex = textSourceCharacterIndex;
            _debugFn?.Invoke($"GetTextRun(textSourceCharacterIndex = {textSourceCharacterIndex})", 5);

            if (textSourceCharacterIndex == 0)
            {
#if DEBUG
                _debugFn?.Invoke($"Clearing runs because at beginning of text source", 4);
#endif
                Runs.Clear();
                SyntaxInfos = GetSyntaxInfos().GetEnumerator();
                if (!SyntaxInfos.MoveNext())
                {
                    var endOfParagraph = new CustomTextEndOfParagraph(2)
                    {
                        Index = textSourceCharacterIndex
                    };
                    Runs.Add(endOfParagraph);
                    return(endOfParagraph);
                }
            }
            else
            {
#if DEBUGRUNS
                foreach (var textRun in Runs)
                {
                    _debugFn?.Invoke("    " + textRun.ToString(), 4);
                }
#endif

                Runs = RunsBefore(textSourceCharacterIndex, Runs).ToList();
            }

            var si = SyntaxInfos.Current;
            if (si == null)
            {
                var endOfParagraph = new CustomTextEndOfParagraph(2)
                {
                    Index = textSourceCharacterIndex
                };
                Runs.Add(endOfParagraph);
                return(endOfParagraph);
            }

            // ReSharper disable once PossibleNullReferenceException
            while (textSourceCharacterIndex > si.Span1.Start ||
                   /*|| si.Span1.End < textSourceCharacterIndex*/ si.Text.Length == 0)
            {
                if (!SyntaxInfos.MoveNext())
                {
                    if (textSourceCharacterIndex < Length)
                    {
                        var len = Length - textSourceCharacterIndex;
                        var buf = new char[len];
                        Text.CopyTo(textSourceCharacterIndex, buf, 0, len);
                        if (len == 2 && buf[0] == '\r' && buf[1] == '\n')
                        {
                            var eol = new CustomTextEndOfLine(2)
                            {
                                Index = textSourceCharacterIndex
                            };
                            Runs.Add(eol);
                            return(eol);
                        }

                        var t = string.Join("", buf);
                        var customTextCharacters = new CustomTextCharacters(t, MakeProperties(SyntaxKind.None, t))
                        {
                            Index = textSourceCharacterIndex
                        };
                        Runs.Add(customTextCharacters);
                        return(customTextCharacters);
                    }

                    var endOfParagraph = new CustomTextEndOfParagraph(2)
                    {
                        Index = textSourceCharacterIndex
                    };
                    Runs.Add(endOfParagraph);
                    return(endOfParagraph);
                }

                si = SyntaxInfos.Current;
            }

            if (textSourceCharacterIndex < si.Span1.Start)
            {
                var len = si.Span1.Start - textSourceCharacterIndex;
                var buf = new char[len];
                Text.CopyTo(textSourceCharacterIndex, buf, 0, len);
                if (len == 2 && buf[0] == '\r' && buf[1] == '\n')
                {
                    var eol = new CustomTextEndOfLine(2)
                    {
                        Index = textSourceCharacterIndex
                    };

                    Runs.Add(eol);
                    return(eol);
                }

                var t  = string.Join("", buf);
                var nl = t.IndexOf("\r\n", StringComparison.Ordinal);
                if (nl != -1)
                {
                    t = t.Substring(0, nl);
                    if (t == "")
                    {
                        var eol = new CustomTextEndOfLine(2)
                        {
                            Index = textSourceCharacterIndex
                        };
                        Runs.Add(eol);
                        return(eol);
                    }

                    var ctc = new CustomTextCharacters(t,
                                                       MakeProperties(SyntaxKind.None, t))
                    {
                        Index = textSourceCharacterIndex
                    };
                    Runs.Add(ctc);
                    return(ctc);
                }

                var customTextCharacters = new CustomTextCharacters(t, MakeProperties(SyntaxKind.None, t))
                {
                    Index = textSourceCharacterIndex
                };
                Runs.Add(customTextCharacters);
                return(customTextCharacters);
            }

            // while (textSourceCharacterIndex > si.Span1.Start)
            // {
            // if (!SyntaxInfos.MoveNext())
            // {

            // }
            // }
            if (textSourceCharacterIndex != si.Span1.Start)
            {
                throw new InvalidOperationException("Character index does not match span start");
            }
            if (si.SyntaxTrivia.HasValue)
            {
                var syntaxKind = CSharpExtensions.Kind(si.SyntaxTrivia.Value);
                if (syntaxKind == SyntaxKind.EndOfLineTrivia || syntaxKind == SyntaxKind.XmlTextLiteralNewLineToken)
                {
                    var customTextEndOfLine = new CustomTextEndOfLine(2)
                    {
                        Index = textSourceCharacterIndex
                    };
                    Runs.Add(customTextEndOfLine);
                    return(customTextEndOfLine);
                }

                var p = PropsFor(si.SyntaxTrivia.Value, si.Text);
                var syntaxTriviaTextCharacters = new SyntaxTriviaTextCharacters(si.Text, p, si.Span1,
                                                                                si.SyntaxTrivia.Value, si.Node, si.Token, si.TriviaPosition, si.StructuredTrivia)
                {
                    Index = si.Span1.Start
                };
                Runs.Add(syntaxTriviaTextCharacters);
                return(syntaxTriviaTextCharacters);
            }

            if (si.SyntaxToken.HasValue)
            {
                if (CSharpExtensions.Kind(si.SyntaxToken.Value) == SyntaxKind.XmlTextLiteralNewLineToken)
                {
                    var customTextEndOfLine = new CustomTextEndOfLine(2)
                    {
                        Index = textSourceCharacterIndex
                    };
                    Runs.Add(customTextEndOfLine);
                    return(customTextEndOfLine);
                }

                var syntaxTokenTextCharacters = new SyntaxTokenTextCharacters(si.Text, si.Text.Length,
                                                                              PropsFor(si.SyntaxToken.Value, si.Text),
                                                                              si.SyntaxToken.Value, si.SyntaxToken.Value.Parent)
                {
                    Index = si.Span1.Start
                };
                Runs.Add(syntaxTokenTextCharacters);
                return(syntaxTokenTextCharacters);
            }

            var textEndOfParagraph = new CustomTextEndOfParagraph(2)
            {
                Index = textSourceCharacterIndex
            };
            Runs.Add(textEndOfParagraph);
            return(textEndOfParagraph);

#if false
            Debug.WriteLine($"index: {textSourceCharacterIndex}");

            TextSpan?TakeToken()
            {
                var includeDocumentationComments = true;
                var includeDirectives            = true;
                var includeSkipped   = true;
                var includeZeroWidth = true;

                token = token.HasValue
                    ? token.Value.GetNextToken(includeZeroWidth, includeSkipped, includeDirectives,
                                               includeDocumentationComments)
                    : Node?.GetFirstToken(includeZeroWidth, includeSkipped, includeDirectives,
                                          includeDocumentationComments);

                if (token.HasValue)
                {
                    if (!_starts.Any() && token.Value.SpanStart != 0)
                    {
                    }

                    var tuple = new StartInfo(token.Value.Span, token.Value);
                    _starts.Add(tuple);
                    DumpStarts();
                    return(token.Value.Span);
                }

                return(null);
            }

            TextSpan?span = null;
            if (textSourceCharacterIndex == 0)
            {
                if (Length == 0)
                {
                    return(new TextEndOfParagraph(2));
                }

                _curStart = 0;

                if (_starts.Any())
                {
                    var startInfo = _starts.First();
                    token  = startInfo.Token;
                    trivia = startInfo.SyntaxTrivia;
                    span   = startInfo.TextSpan;
                    if (token.HasValue)
                    {
                        CheckToken(token);
                    }
                }

                // _starts.Clear();
                DumpStarts();
            }
            else
            {
                var startInfo = _starts[_curStart];
                token  = startInfo.Token;
                trivia = startInfo.SyntaxTrivia;
                span   = startInfo.TextSpan;
                if (token.HasValue)
                {
                    CheckToken(token);
                }
            }

            try
            {
                var childInPos = Node.ChildThatContainsPosition(textSourceCharacterIndex);
                if (childInPos.IsNode)
                {
                    var n = childInPos.AsNode();
                    if (textSourceCharacterIndex < n.SpanStart)
                    {
                        foreach (var syntaxTrivia in n.GetLeadingTrivia())
                        {
                            if (textSourceCharacterIndex >= syntaxTrivia.SpanStart &&
                                textSourceCharacterIndex < syntaxTrivia.Span.End)
                            {
                                Debug.WriteLine("In trivia " + syntaxTrivia);
                                if (textSourceCharacterIndex > syntaxTrivia.SpanStart)
                                {
                                    Debug.WriteLine("In middle of trivia");
                                }

                                var characterString = syntaxTrivia.ToFullString();
                                return(new SyntaxTriviaTextCharacters(characterString,
                                                                      PropsFor(syntaxTrivia, characterString), syntaxTrivia.FullSpan, syntaxTrivia, null,
                                                                      null, TriviaPosition.Leading));
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }


            var token1 = token;
            // Debug.WriteLine("Index = " + textSourceCharacterIndex);
            // if (!token1.HasValue)
            // {
            // span = TakeToken();
            // if (!this.token.HasValue) return new TextEndOfParagraph(2);
            // token1 = this.token;

            // }

//            var token = token1.Value;
            if (!span.HasValue)
            {
                throw new InvalidOperationException();
            }
            var k = span.Value;

            if (textSourceCharacterIndex < k.Start)
            {
                var len = k.Start - textSourceCharacterIndex;
                var buf = new char[len];
                Text.CopyTo(textSourceCharacterIndex, buf, 0, len);
                if (len == 2 && buf[0] == '\r' && buf[1] == '\n')
                {
                    return(new CustomTextEndOfLine(2));
                }

                var t = string.Join("", buf);
                return(new CustomTextCharacters(t, MakeProperties(SyntaxKind.None, t)));
            }
            else if (textSourceCharacterIndex >= k.End && k.Length != 0)
            {
                TakeToken();
                return(GetTextRun(textSourceCharacterIndex));
            }
            else
            {
                if (trivia.HasValue)
                {
                    var syntaxTrivia1 = trivia.Value;
                    var q             = syntaxTrivia1.Token.LeadingTrivia
                                        .SkipWhile(syntaxTrivia => syntaxTrivia != syntaxTrivia1)
                                        .Skip(1);
                    if (q.Any())
                    {
                        _curStart++;
                        var startInfo = new StartInfo(q.First());
                        if (_starts.Count <= _curStart)
                        {
                            _starts.Add(startInfo);
                        }
                        else
                        {
                            _starts[_curStart] = startInfo;
                        }
                    }
                    else
                    {
                        var t2 = syntaxTrivia1.Token.GetNextToken(true, true, true, true);
                        if (t2.HasLeadingTrivia)
                        {
                            var st = new StartInfo(t2.LeadingTrivia.First());
                            _curStart++;
                            if (_starts.Count <= _curStart)
                            {
                                _starts.Add(st);
                            }
                            else
                            {
                                _starts[_curStart] = st;
                            }
                        }
                        else if (CSharpExtensions.Kind(t2) != SyntaxKind.None)
                        {
                            var st = new StartInfo(t2.Span, t2);
                            _curStart++;
                            if (_starts.Count <= _curStart)
                            {
                                _starts.Add(st);
                            }
                            else
                            {
                                _starts[_curStart] = st;
                            }
                        }
                    }

                    var t = syntaxTrivia1.ToFullString();
                    return(new SyntaxTriviaTextCharacters(t, PropsFor(trivia.Value, t), span.Value, syntaxTrivia1, null,
                                                          null, TriviaPosition.Leading));
                }

                if (token.HasValue && (CSharpExtensions.Kind(token.Value) == SyntaxKind.None ||
                                       CSharpExtensions.Kind(token.Value) == SyntaxKind.EndOfFileToken))
                {
                    return(new TextEndOfParagraph(2));
                }
                var token0 = token.Value;
                if (CSharpExtensions.Kind(token0) == SyntaxKind.EndOfLineTrivia)
                {
                    return(new CustomTextEndOfLine(2));
                }
                var len = k.Length;
                if (len == 0)
                {
                    TakeToken();
                    return(GetTextRun(textSourceCharacterIndex));
                }

                TakeToken();
                if (token0.Text.Length != len)
                {
                }

                return(new CustomTextCharacters(token0.Text, MakeProperties(token, token0.Text)));
            }
#endif
        }
示例#7
0
        protected virtual void ConfigureEvent()
        {
            Runs.Add(new NascarPracticeRun()
            {
                SeriesId = Series.SeriesId,
                Round    = 1,
                RunType  = NascarRunType.Practice1,
                RunId    = Runs.Count + 1,
                StartLap = 1,
                EndLap   = 999
            });
            Runs.Add(new NascarPracticeRun()
            {
                SeriesId = Series.SeriesId,
                Round    = 2,
                RunType  = NascarRunType.Practice2,
                RunId    = Runs.Count + 1,
                StartLap = 1,
                EndLap   = 999
            });
            Runs.Add(new NascarPracticeRun()
            {
                SeriesId = Series.SeriesId,
                Round    = 3,
                RunType  = NascarRunType.FinalPractice,
                RunId    = Runs.Count + 1,
                StartLap = 1,
                EndLap   = 999
            });

            Runs.Add(new NascarQualifyingRun()
            {
                SeriesId = Series.SeriesId,
                Round    = 1,
                RunType  = NascarRunType.QualifyingStage1,
                RunId    = Runs.Count + 1,
                StartLap = 1,
                EndLap   = 999
            });
            Runs.Add(new NascarQualifyingRun()
            {
                SeriesId = Series.SeriesId,
                Round    = 2,
                RunType  = NascarRunType.QualifyingStage2,
                RunId    = Runs.Count + 1,
                StartLap = 1,
                EndLap   = 999
            });
            Runs.Add(new NascarQualifyingRun()
            {
                SeriesId = Series.SeriesId,
                Round    = 3,
                RunType  = NascarRunType.FinalQualifyingStage,
                RunId    = Runs.Count + 1,
                StartLap = 1,
                EndLap   = 999
            });

            var totalRaceLaps    = (int)(Track.RaceLengthBase * Series.RaceLapPercent);
            var stage1Length     = (int)(totalRaceLaps * Series.RaceStage1Percent);
            var stage2Length     = (int)(totalRaceLaps * Series.RaceStage2Percent);
            var finalStageLength = (int)(totalRaceLaps * Series.RaceFinalStagePercent);

            Runs.Add(new NascarRaceRun()
            {
                SeriesId = Series.SeriesId,
                RunType  = NascarRunType.RaceStage1,
                RunId    = Runs.Count + 1,
                StartLap = 1,
                EndLap   = stage1Length
            });
            Runs.Add(new NascarRaceRun()
            {
                SeriesId = Series.SeriesId,
                RunType  = NascarRunType.RaceStage2,
                RunId    = Runs.Count + 1,
                StartLap = stage1Length + 1,
                EndLap   = stage1Length + stage2Length
            });
            Runs.Add(new NascarRaceRun()
            {
                SeriesId = Series.SeriesId,
                RunType  = NascarRunType.FinalRaceStage,
                RunId    = Runs.Count + 1,
                StartLap = stage1Length + stage2Length + 1,
                EndLap   = totalRaceLaps
            });
        }
示例#8
0
 /// <summary>
 /// Adds a run to the list of runs.
 /// </summary>
 /// <param name="activity">The run to add.</param>
 public void AddRun(ActivitySummary activity)
 {
     Runs.Add(activity);
 }
示例#9
0
 public virtual void AddRun(Run run)
 {
     run.Trial = this;
     Runs.Add(run);
 }
        void MailMerge_MergeField(object sender, Aspose.Words.Reporting.MergeFieldEventArgs e)
        {
            #region 科目成績

            if (e.FieldName == "科目成績起始位置")
            {
                object[] objectValue = (object[])e.FieldValue;
                Dictionary <SemesterSubjectScoreInfo, Dictionary <string, string> > subjectScore = (Dictionary <SemesterSubjectScoreInfo, Dictionary <string, string> >)objectValue[0];
                string        resitSign  = (string)objectValue[1];
                string        repeatSign = (string)objectValue[2];
                StudentRecord studRec    = (StudentRecord)objectValue[3];

                DocumentBuilder builder = new DocumentBuilder(e.Document);
                builder.MoveToField(e.Field, false);

                Table SSTable = ((Row)((Cell)builder.CurrentParagraph.ParentNode).ParentRow).ParentTable;

                int SSRowNumber     = SSTable.Rows.Count - 1;
                int SSTableRowIndex = 1;
                int SSTableColIndex = 0;
                int MaxSubjectCount = SSRowNumber * 2;

                try
                {
                    // 當科目數超過範本可存放數,不列入處理
                    if (subjectScore.Keys.Count > MaxSubjectCount)
                    {
                        if (_ErrorMessage.Length < 1)
                        {
                            _ErrorMessage.AppendLine("產生資料發生錯誤:學生成績科目數超過範本可顯示科目數:" + MaxSubjectCount + " ,請調整範本科目數後再列印");
                        }

                        string className = "";
                        if (studRec.RefClass != null)
                        {
                            className = studRec.RefClass.ClassName;
                        }
                        string ErrMsg = "學號:" + studRec.StudentNumber + ",班級:" + className + "座號:" + studRec.SeatNo + ",姓名:" + studRec.StudentName + ", 學生成績科目數:" + subjectScore.Keys.Count;
                        _ErrorMessage.AppendLine(ErrMsg);
                    }
                    else
                    {
                        List <SemesterSubjectScoreInfo> sortList = new List <SemesterSubjectScoreInfo>();
                        sortList.AddRange(subjectScore.Keys);
                        sortList.Sort(SortBySemesterSubjectScoreInfo);

                        foreach (SemesterSubjectScoreInfo info in sortList)
                        {
                            Runs runs = SSTable.Rows[SSTableRowIndex].Cells[SSTableColIndex].Paragraphs[0].Runs;
                            runs.Add(new Run(e.Document));
                            runs[runs.Count - 1].Text      = subjectScore[info]["科目"] + ((string.IsNullOrEmpty(subjectScore[info]["級別"])) ? "" : (" (" + subjectScore[info]["級別"] + ")"));
                            runs[runs.Count - 1].Font.Size = 10;
                            runs[runs.Count - 1].Font.Name = "新細明體";

                            SSTable.Rows[SSTableRowIndex].Cells[SSTableColIndex + 1].Paragraphs[0].Runs.Add(new Run(e.Document, subjectScore[info]["必修"] + subjectScore[info]["學分"]));
                            SSTable.Rows[SSTableRowIndex].Cells[SSTableColIndex + 1].Paragraphs[0].Runs[0].Font.Size = 10;
                            SSTable.Rows[SSTableRowIndex].Cells[SSTableColIndex + 2].Paragraphs[0].Runs.Add(new Run(e.Document, subjectScore[info]["分數"]));
                            SSTable.Rows[SSTableRowIndex].Cells[SSTableColIndex + 2].Paragraphs[0].Runs[0].Font.Size = 10;

                            int    colshift = 0;
                            string re       = "";
                            if (subjectScore[info].ContainsKey("補考"))
                            {
                                if (subjectScore[info]["補考"] == "是")
                                {
                                    re = resitSign;
                                }
                                else if (subjectScore[info]["補考"] == "否")
                                {
                                    re = repeatSign;
                                }
                            }

                            SSTable.Rows[SSTableRowIndex].Cells[SSTableColIndex + 3 + colshift].Paragraphs[0].Runs.Add(new Run(e.Document, re));
                            SSTable.Rows[SSTableRowIndex].Cells[SSTableColIndex + 3 + colshift].Paragraphs[0].Runs[0].Font.Size = 10;

                            SSTableRowIndex++;
                            if (SSTableRowIndex > SSRowNumber)
                            {
                                SSTableRowIndex  = 1;
                                SSTableColIndex += 4;
                            }
                        }
                    }
                    e.Text = string.Empty;
                }
                catch (Exception ex)
                {
                    SmartSchool.ExceptionHandler.BugReporter.ReportException(ex, true);
                }
            }

            #endregion

            #region 分項成績

            if (e.FieldName == "分項成績起始位置")
            {
                object[] objectValue = (object[])e.FieldValue;
                Dictionary <string, Dictionary <string, string> > entryScore = (Dictionary <string, Dictionary <string, string> >)objectValue[0];
                Dictionary <string, string> totalCredit = (Dictionary <string, string>)objectValue[1];
                bool over100 = (bool)objectValue[2];

                DocumentBuilder builder = new DocumentBuilder(e.Document);
                builder.MoveToField(e.Field, false);

                Table ESTable = ((Row)((Cell)builder.CurrentParagraph.ParentNode).ParentRow).ParentTable;

                int ESRowNumber     = ESTable.Rows.Count - 1;
                int ESTableRowIndex = 1;
                int ESTableColIndex = 0;

                List <string> sortList = new List <string>();
                sortList.AddRange(entryScore.Keys);
                sortList.Sort(SortByEntryName);

                foreach (string entry in sortList)
                {
                    // 先過濾分項原始)
                    if (entry.Contains("(原始)"))
                    {
                        continue;
                    }

                    string semesterDegree = "";
                    if (entry == "德行" || entry == "學年德行成績")
                    {
                        decimal moralScore = decimal.Parse(entryScore[entry]["分數"]);
                        if (!over100 && moralScore > 100)
                        {
                            entryScore[entry]["分數"] = "100";
                        }
                        semesterDegree = " / " + ParseLevel(moralScore);
                    }

                    Runs runs = ESTable.Rows[ESTableRowIndex].Cells[ESTableColIndex].Paragraphs[0].Runs;

                    runs.Add(new Run(e.Document, ToDisplayName(entry)));
                    runs[runs.Count - 1].Font.Size = 10;
                    ESTable.Rows[ESTableRowIndex].Cells[ESTableColIndex + 1].Paragraphs[0].Runs.Add(new Run(e.Document, entryScore[entry]["分數"] + semesterDegree));
                    ESTable.Rows[ESTableRowIndex].Cells[ESTableColIndex + 1].Paragraphs[0].Runs[0].Font.Size = 10;

                    ESTableRowIndex++;
                    if (ESTableRowIndex > ESRowNumber)
                    {
                        ESTableRowIndex  = 1;
                        ESTableColIndex += 2;
                    }
                }

                foreach (string key in totalCredit.Keys)
                {
                    Runs runs = ESTable.Rows[ESTableRowIndex].Cells[ESTableColIndex].Paragraphs[0].Runs;

                    runs.Add(new Run(e.Document, key));
                    runs[runs.Count - 1].Font.Size = 10;
                    ESTable.Rows[ESTableRowIndex].Cells[ESTableColIndex + 1].Paragraphs[0].Runs.Add(new Run(e.Document, totalCredit[key]));
                    ESTable.Rows[ESTableRowIndex].Cells[ESTableColIndex + 1].Paragraphs[0].Runs[0].Font.Size = 10;

                    ESTableRowIndex++;
                    if (ESTableRowIndex > ESRowNumber)
                    {
                        ESTableRowIndex  = 1;
                        ESTableColIndex += 2;
                    }
                }

                e.Text = string.Empty;
            }

            #endregion

            #region 缺曠紀錄

            if (e.FieldName == "缺曠紀錄")
            {
                object[] objectValue = (object[])e.FieldValue;

                if ((Dictionary <string, List <string> >)objectValue[0] == null || ((Dictionary <string, List <string> >)objectValue[0]).Count == 0)
                {
                    e.Text = string.Empty;
                    return;
                }

                Dictionary <string, List <string> > userType    = (Dictionary <string, List <string> >)objectValue[0];
                Dictionary <string, int>            absenceInfo = (Dictionary <string, int>)objectValue[1];

                #region 產生缺曠紀錄表格

                DocumentBuilder builder = new DocumentBuilder(e.Document);
                builder.MoveToField(e.Field, false);

                int    ARowNumber = 3;
                double AWidth     = 0;
                double AHeight    = 0;
                double ARowHeight = 0;

                int    AColumn      = 0;
                double AMicroColumn = 0;

                foreach (string periodType in userType.Keys)
                {
                    AColumn += userType[periodType].Count;
                }

                Cell ACell = (Cell)builder.CurrentParagraph.ParentNode;

                AWidth       = ACell.CellFormat.Width;
                AHeight      = (ACell.ParentNode as Row).RowFormat.Height;
                ARowHeight   = (AHeight) / (ARowNumber);
                AMicroColumn = AWidth / (double)AColumn;

                builder.StartTable();
                builder.CellFormat.ClearFormatting();
                builder.RowFormat.HeightRule            = HeightRule.Exactly;
                builder.RowFormat.Height                = ARowHeight;
                builder.RowFormat.Alignment             = RowAlignment.Center;
                builder.CellFormat.VerticalAlignment    = CellVerticalAlignment.Center;
                builder.CellFormat.LeftPadding          = 0.0;
                builder.CellFormat.RightPadding         = 0.0;
                builder.ParagraphFormat.Alignment       = ParagraphAlignment.Center;
                builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly;
                builder.ParagraphFormat.LineSpacing     = 10;
                builder.Font.Size = 10;

                foreach (string periodType in userType.Keys)
                {
                    builder.InsertCell().CellFormat.Width = AMicroColumn * userType[periodType].Count;
                    builder.Write(periodType);
                }

                builder.EndRow();

                foreach (string periodType in userType.Keys)
                {
                    foreach (string absence in userType[periodType])
                    {
                        builder.InsertCell().CellFormat.Width = AMicroColumn;
                        builder.Write(absence);
                    }
                }

                builder.EndRow();

                foreach (string periodType in userType.Keys)
                {
                    foreach (string absence in userType[periodType])
                    {
                        builder.InsertCell().CellFormat.Width = AMicroColumn;
                        builder.Write(absenceInfo[periodType + "_" + absence].ToString());
                    }
                }

                builder.EndRow();

                Table ATable = builder.EndTable();

                //去除表格四邊的線
                foreach (Cell cell in ATable.FirstRow.Cells)
                {
                    cell.CellFormat.Borders.Top.LineStyle = LineStyle.None;
                }

                foreach (Cell cell in ATable.LastRow.Cells)
                {
                    cell.CellFormat.Borders.Bottom.LineStyle = LineStyle.None;
                }

                foreach (Row row in ATable.Rows)
                {
                    row.FirstCell.CellFormat.Borders.Left.LineStyle = LineStyle.None;
                    row.LastCell.CellFormat.Borders.Right.LineStyle = LineStyle.None;
                }

                #endregion

                #region 填入缺曠紀錄資料
                #endregion

                e.Text = string.Empty;
            }

            #endregion
        }
示例#11
0
        private void MailMerge_MergeField(object sender, Aspose.Words.Reporting.MergeFieldEventArgs e)
        {
            #region 科目成績

            if (e.FieldName == "科目成績起始位置")
            {
                object[] objectValue = (object[])e.FieldValue;
                Dictionary <SemesterSubjectScoreInfo, Dictionary <string, string> > subjectScore = (Dictionary <SemesterSubjectScoreInfo, Dictionary <string, string> >)objectValue[0];
                string resitSign  = (string)objectValue[1];
                string repeatSign = (string)objectValue[2];

                DocumentBuilder builder = new DocumentBuilder(e.Document);
                builder.MoveToField(e.Field, false);

                Table SSTable = ((Row)((Cell)builder.CurrentParagraph.ParentNode).ParentRow).ParentTable;

                int SSRowNumber     = SSTable.Rows.Count - 1;
                int SSTableRowIndex = 1;
                int SSTableColIndex = 0;

                List <SemesterSubjectScoreInfo> sortList = new List <SemesterSubjectScoreInfo>();
                sortList.AddRange(subjectScore.Keys);
                sortList.Sort(SortBySemesterSubjectScoreInfo);

                foreach (SemesterSubjectScoreInfo info in sortList)
                {
                    if (SSTable.Rows[SSTableRowIndex].Cells[SSTableColIndex] == null)
                    {
                        throw new ArgumentException("科目成績表格不足容下所有科目成績。");
                    }

                    Runs runs = SSTable.Rows[SSTableRowIndex].Cells[SSTableColIndex].Paragraphs[0].Runs;
                    runs.Add(new Run(e.Document));
                    runs[runs.Count - 1].Text      = subjectScore[info]["科目"] + ((string.IsNullOrEmpty(subjectScore[info]["級別"])) ? "" : (" (" + subjectScore[info]["級別"] + ")"));
                    runs[runs.Count - 1].Font.Size = 10;
                    runs[runs.Count - 1].Font.Name = "新細明體";

                    SSTable.Rows[SSTableRowIndex].Cells[SSTableColIndex + 1].Paragraphs[0].Runs.Add(new Run(e.Document, subjectScore[info]["必修"] + subjectScore[info]["學分"]));
                    SSTable.Rows[SSTableRowIndex].Cells[SSTableColIndex + 1].Paragraphs[0].Runs[0].Font.Size = 10;
                    SSTable.Rows[SSTableRowIndex].Cells[SSTableColIndex + 2].Paragraphs[0].Runs.Add(new Run(e.Document, subjectScore[info]["分數"]));
                    SSTable.Rows[SSTableRowIndex].Cells[SSTableColIndex + 2].Paragraphs[0].Runs[0].Font.Size = 10;

                    int    colshift = 0;
                    string re       = "";
                    if (subjectScore[info].ContainsKey("補考"))
                    {
                        if (subjectScore[info]["補考"] == "是")
                        {
                            re = resitSign;
                        }
                        else if (subjectScore[info]["補考"] == "否")
                        {
                            re = repeatSign;
                        }
                    }

                    SSTable.Rows[SSTableRowIndex].Cells[SSTableColIndex + 3 + colshift].Paragraphs[0].Runs.Add(new Run(e.Document, re));
                    SSTable.Rows[SSTableRowIndex].Cells[SSTableColIndex + 3 + colshift].Paragraphs[0].Runs[0].Font.Size = 10;

                    SSTableRowIndex++;
                    if (SSTableRowIndex > SSRowNumber)
                    {
                        SSTableRowIndex  = 1;
                        SSTableColIndex += 4;
                    }
                }

                e.Text = string.Empty;
            }

            #endregion

            #region 分項成績

            if (e.FieldName == "分項成績起始位置")
            {
                object[] objectValue = (object[])e.FieldValue;
                Dictionary <string, Dictionary <string, string> > entryScore = (Dictionary <string, Dictionary <string, string> >)objectValue[0];
                Dictionary <string, string> totalCredit = (Dictionary <string, string>)objectValue[1];
                bool over100 = (bool)objectValue[2];

                DocumentBuilder builder = new DocumentBuilder(e.Document);
                builder.MoveToField(e.Field, false);

                Table ESTable = ((Row)((Cell)builder.CurrentParagraph.ParentNode).ParentRow).ParentTable;

                int ESRowNumber     = ESTable.Rows.Count - 1;
                int ESTableRowIndex = 1;
                int ESTableColIndex = 0;

                List <string> sortList = new List <string>();
                sortList.AddRange(entryScore.Keys);
                sortList.Sort(SortByEntryName);

                foreach (string entry in sortList)
                {
                    // 先過濾分項原始)
                    if (entry.Contains("(原始)"))
                    {
                        continue;
                    }

                    string semesterDegree = "";
                    if (entry == "德行" || entry == "學年德行成績")
                    {
                        continue;

                        //decimal moralScore = decimal.Parse(entryScore[entry]["分數"]);
                        //if (!over100 && moralScore > 100)
                        //    entryScore[entry]["分數"] = "100";
                        //semesterDegree = " / " + ParseLevel(moralScore);
                    }

                    Runs runs = ESTable.Rows[ESTableRowIndex].Cells[ESTableColIndex].Paragraphs[0].Runs;

                    runs.Add(new Run(e.Document, ToDisplayName(entry)));
                    runs[runs.Count - 1].Font.Size = 10;
                    ESTable.Rows[ESTableRowIndex].Cells[ESTableColIndex + 1].Paragraphs[0].Runs.Add(new Run(e.Document, entryScore[entry]["分數"] + semesterDegree));
                    ESTable.Rows[ESTableRowIndex].Cells[ESTableColIndex + 1].Paragraphs[0].Runs[0].Font.Size = 10;

                    ESTableRowIndex++;
                    if (ESTableRowIndex > ESRowNumber)
                    {
                        ESTableRowIndex  = 1;
                        ESTableColIndex += 2;
                    }
                }

                foreach (string key in totalCredit.Keys)
                {
                    Runs runs = ESTable.Rows[ESTableRowIndex].Cells[ESTableColIndex].Paragraphs[0].Runs;

                    runs.Add(new Run(e.Document, key));
                    runs[runs.Count - 1].Font.Size = 10;
                    ESTable.Rows[ESTableRowIndex].Cells[ESTableColIndex + 1].Paragraphs[0].Runs.Add(new Run(e.Document, totalCredit[key]));
                    ESTable.Rows[ESTableRowIndex].Cells[ESTableColIndex + 1].Paragraphs[0].Runs[0].Font.Size = 10;

                    ESTableRowIndex++;
                    if (ESTableRowIndex > ESRowNumber)
                    {
                        ESTableRowIndex  = 1;
                        ESTableColIndex += 2;
                    }
                }

                e.Text = string.Empty;
            }

            #endregion

            #region 缺曠紀錄

            if (e.FieldName == "缺曠紀錄")
            {
                object[] objectValue = (object[])e.FieldValue;

                if ((Dictionary <string, List <string> >)objectValue[0] == null || ((Dictionary <string, List <string> >)objectValue[0]).Count == 0)
                {
                    e.Text = string.Empty;
                    return;
                }

                Dictionary <string, List <string> > userType    = (Dictionary <string, List <string> >)objectValue[0];
                Dictionary <string, int>            absenceInfo = (Dictionary <string, int>)objectValue[1];

                #region 產生缺曠紀錄表格

                DocumentBuilder builder = new DocumentBuilder(e.Document);
                builder.MoveToField(e.Field, false);

                int    ARowNumber = 3;
                double AWidth     = 0;
                double AHeight    = 0;
                double ARowHeight = 0;

                int    AColumn      = 0;
                double AMicroColumn = 0;

                foreach (string periodType in userType.Keys)
                {
                    AColumn += userType[periodType].Count;
                }

                Cell ACell = (Cell)builder.CurrentParagraph.ParentNode;

                AWidth       = ACell.CellFormat.Width;
                AHeight      = (ACell.ParentNode as Row).RowFormat.Height;
                ARowHeight   = (AHeight) / (ARowNumber);
                AMicroColumn = AWidth / (double)AColumn;

                builder.StartTable();
                builder.CellFormat.ClearFormatting();
                builder.RowFormat.HeightRule            = HeightRule.Exactly;
                builder.RowFormat.Height                = ARowHeight;
                builder.RowFormat.Alignment             = RowAlignment.Center;
                builder.CellFormat.VerticalAlignment    = CellVerticalAlignment.Center;
                builder.CellFormat.LeftPadding          = 0.0;
                builder.CellFormat.RightPadding         = 0.0;
                builder.ParagraphFormat.Alignment       = ParagraphAlignment.Center;
                builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly;
                builder.ParagraphFormat.LineSpacing     = 10;
                builder.Font.Size = 10;

                foreach (string periodType in userType.Keys)
                {
                    builder.InsertCell().CellFormat.Width = AMicroColumn * userType[periodType].Count;
                    builder.Write(periodType);
                }

                builder.EndRow();

                foreach (string periodType in userType.Keys)
                {
                    foreach (string absence in userType[periodType])
                    {
                        builder.InsertCell().CellFormat.Width = AMicroColumn;
                        builder.Write(absence);
                    }
                }

                builder.EndRow();

                foreach (string periodType in userType.Keys)
                {
                    foreach (string absence in userType[periodType])
                    {
                        builder.InsertCell().CellFormat.Width = AMicroColumn;
                        builder.Write(absenceInfo[periodType + "_" + absence].ToString());
                    }
                }

                builder.EndRow();

                Table ATable = builder.EndTable();

                //去除表格四邊的線
                foreach (Cell cell in ATable.FirstRow.Cells)
                {
                    cell.CellFormat.Borders.Top.LineStyle = LineStyle.None;
                }

                foreach (Cell cell in ATable.LastRow.Cells)
                {
                    cell.CellFormat.Borders.Bottom.LineStyle = LineStyle.None;
                }

                foreach (Row row in ATable.Rows)
                {
                    row.FirstCell.CellFormat.Borders.Left.LineStyle = LineStyle.None;
                    row.LastCell.CellFormat.Borders.Right.LineStyle = LineStyle.None;
                }

                #endregion

                #region 填入缺曠紀錄資料
                #endregion

                e.Text = string.Empty;
            }

            #endregion

            #region 綜合表現(文字評量)

            if (e.FieldName == "綜合表現")
            {
                XmlElement objectValue = (XmlElement)e.FieldValue;

                if (objectValue != null)
                {
                    DocumentBuilder builder = new DocumentBuilder(e.Document);
                    builder.MoveToField(e.Field, false);

                    Cell temp;

                    double width = (builder.CurrentParagraph.ParentNode as Cell).CellFormat.Width;

                    builder.StartTable();
                    //builder.CellFormat.ClearFormatting();
                    foreach (XmlElement each in objectValue.SelectNodes("TextScore/Morality"))
                    {
                        string face = each.GetAttribute("Face");

                        //如果學生身上的face不存在對照表上,就不印出來
                        if ((SmartSchool.Customization.Data.SystemInformation.Fields["文字評量對照表"] as XmlElement).SelectSingleNode("Content/Morality[@Face='" + face + "']") == null)
                        {
                            continue;
                        }

                        string comment = each.InnerText;

                        temp = builder.InsertCell();
                        temp.CellFormat.LeftPadding        = 5;
                        temp.CellFormat.Width              = 120;
                        temp.ParentRow.RowFormat.Alignment = RowAlignment.Left;
                        temp.CellFormat.VerticalAlignment  = CellVerticalAlignment.Center;
                        builder.Write(face);

                        temp = builder.InsertCell();
                        temp.CellFormat.LeftPadding        = 5;
                        temp.CellFormat.Width              = width - 120;
                        temp.ParentRow.RowFormat.Alignment = RowAlignment.Left;
                        temp.CellFormat.VerticalAlignment  = CellVerticalAlignment.Center;
                        builder.Write(comment);
                        builder.EndRow();
                    }
                    Table table = builder.EndTable();

                    if (table.Rows.Count > 0)
                    {
                        foreach (Cell each in table.FirstRow.Cells)
                        {
                            each.CellFormat.Borders.Top.LineStyle = LineStyle.None;
                        }

                        foreach (Cell each in table.LastRow.Cells)
                        {
                            each.CellFormat.Borders.Bottom.LineStyle = LineStyle.None;
                        }

                        foreach (Row each in table.Rows)
                        {
                            each.FirstCell.CellFormat.Borders.Left.LineStyle = LineStyle.None;
                            each.LastCell.CellFormat.Borders.Right.LineStyle = LineStyle.None;
                        }
                    }

                    e.Field.Remove();
                }
            }
            #endregion
        }