private void printRingForUser(UserShows userShow, int UserID, Document doc, ref List<int> defaultUsers, ref int pageCount)
        {
            float[] ringColumns = new float[] { 300, 300, 300, 300 };

            User currentUser = new User(userShow.Userid);
            Shows show = new Shows(userShow.ShowID);

            List<ShowDetails> showDetailsList = ShowDetails.GetShowDetails(userShow.ShowID);

            Rings r = new Rings();
            DataSet ringList = r.GetAllRingsForShow(userShow.ShowID, "ShowDate");

            Dogs d = new Dogs();

            DogClasses dc = new DogClasses();
            DateTime dt = DateTime.Now;
            string currentJudge = "";
            int currentRingID = 0;
            int ShowDetailsID = -1;
            int PrevShowDetailsID = -1;
            PdfPTable rings = new PdfPTable(ringColumns);

            int ringCnt = 0;
            PdfPCell cell = null;
            PdfPTable ringDetails = null;
            PdfPTable classDetailsTable = null;
            List<int> dogsRunningToday = new List<int>();
            PdfPTable headerPage = null;
            List<TeamPairsTrioDto> pairsTeams = new List<TeamPairsTrioDto>();
            try
            {
                foreach (DataRow ringRow in ringList.Tables[0].Rows)
                {
                    Rings ring = new Rings(ringRow);
                    int RingID = Convert.ToInt32(ringRow["RingID"]);
                    int EntryType = Convert.ToInt32(ringRow["EntryType"]);
                    int Lho = Convert.ToInt32(ringRow["Lho"]);
                    ShowDetailsID = Convert.ToInt32(ringRow["ShowDetailsID"]);

                    if (ringRow.IsNull("ClassID"))
                    {
                        continue;
                    }
                    int ClassID = Convert.ToInt32(ringRow["ClassID"]);
                    int ClassNo = Convert.ToInt32(ringRow["ClsNo"]);
                    DateTime rowDT = Convert.ToDateTime(ringRow["ShowDate"]);
                    if (rowDT != dt)
                    {
                        if (currentRingID != 0)
                        {
                            if (ringCnt % MaxColumns != 0)
                            {
                                var remind = ringCnt % MaxColumns;
                                while (remind-- > 0)
                                {
                                    cell = new PdfPCell(new Phrase(new Chunk(" ", pageFont)));
                                    cell.BorderWidth = 0;
                                    rings.AddCell(cell);
                                }
                            }
                            if (dogsRunningToday.Count() > 0 || UserID == -1)
                            {
                                doc.Add(headerPage);
                                doc.Add(rings);
                                if (UserID > -1)
                                {
                                    if (currentUser.UserID != UserID)
                                    {
                                        User defaultHandler = new User(UserID);
                                    }
                                }

                                doc.NewPage();
                                pageCount++;
                            }
                        }

                        dogsRunningToday.Clear();
                        if (UserID > -1)
                        {
                            if (currentUser.UserID == UserID)
                            {
                                headerPage = DrawHeader(show, rowDT, currentUser, userShow);
                            }
                            else
                            {
                                User defaultHandler = new User(UserID);
                                headerPage = DrawHeader(show, rowDT, defaultHandler, userShow);
                            }
                        }
                        else
                        {
                            headerPage = DrawHeader(show, rowDT, null, null);

                        }
                        dt = rowDT;
                        rings = new PdfPTable(ringColumns);
                        rings.WidthPercentage = 100;
                        ringCnt = 0;
                    }

                    if (currentRingID != RingID)
                    {
                        currentJudge = "";
                        ringCnt++;
                        ringDetails = new PdfPTable(1);
                        rings.AddCell(new PdfPCell(ringDetails));

                        //List<Judge> judgeList = Judge.getJudgesForRingList(RingID);
                        string JudgeName = Judge.getJudgeForClass(ClassID).Name;
                        int ClsCount = DogClasses.GetDogsInRing(RingID);

                        cell = new PdfPCell(new Phrase(new Chunk(string.Format("Ring No {0} ({1})", ringRow["RingNo"].ToString(), ClsCount), judgeFont)));
                        cell.BorderWidth = 0;
                        cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        ringDetails.AddCell(cell);

                        if (currentJudge != JudgeName)
                        {
                            cell = new PdfPCell(new Phrase(new Chunk(Fpp.Core.Utils.TitleCaseString(JudgeName), judgeFont)));
                            cell.BorderWidth = 0;
                            cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                            ringDetails.AddCell(cell);
                            currentJudge = JudgeName;
                        }
                        currentRingID = RingID;
                        classDetailsTable = new PdfPTable(DetailsColWidths);
                        classDetailsTable.DefaultCell.BorderWidth = 0;
                        ringDetails.AddCell(classDetailsTable);
                    }
                    else
                    {
                        string JudgeName = Judge.getJudgeForClass(ClassID).Name;
                        if (currentJudge != JudgeName)
                        {
                            cell = new PdfPCell(new Phrase(new Chunk("  ", judgeFont)));
                            cell.BorderWidth = 0;
                            cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                            ringDetails.AddCell(cell);
                            cell = new PdfPCell(new Phrase(new Chunk(Fpp.Core.Utils.TitleCaseString(JudgeName), judgeFont)));
                            cell.BorderWidth = 0;
                            cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                            ringDetails.AddCell(cell);

                            classDetailsTable = new PdfPTable(DetailsColWidths);
                            classDetailsTable.DefaultCell.BorderWidth = 0;
                            ringDetails.AddCell(classDetailsTable);
                            currentJudge = JudgeName;
                        }
                    }
                    DataSet dogsList = d.GetDogsInClass(userShow.Userid, ClassID);
                    int dogsInClass = d.dogsInClassCount(ClassID);
                    List<DogClassCount> dcCounts = DogClasses.GetEntryCountsByClassId(userShow.ShowID, ClassID);

                    String clsName;
                    var part = Convert.ToInt32(ringRow["Part"]);
                    var lhoInd = "";
                    var dogsInClassDisplay = "";
                    if (dcCounts.Count > 1)
                    {
                        if (Lho == 1) {
                            dogsInClassDisplay = String.Format("({0}/{1})", dcCounts[0].Count, dcCounts[1].Count);
                        }
                        else
                        {
                            dogsInClassDisplay = String.Format("({0}/{1})", dcCounts[1].Count, dcCounts[0].Count);
                        }
                    }
                    else
                    {
                        dogsInClassDisplay = String.Format("({0})", dogsInClass);
                    }

                    if (Lho == 1)
                    {
                        lhoInd = "(FH 1st)";
                    }
                    else if (Lho == 2)
                    {
                        lhoInd = "(LHO 1st)";
                    }
                    if (EntryType != 10)
                    {
                        clsName = new ShowClasses(ClassID).NormalName(withClassNo:false, useAbbrFlag:true);
                    }
                    else
                    {
                        clsName = String.Format("{0} {1} {2} ",
                                        ShowClasses.expandHeight(ringRow),
                                        ringRow["LongName"].ToString().Trim(),
                                        ringRow["name"].ToString().Trim());
                    }
                    clsName = clsName.Replace("(Special Class", "S");
                    clsName = clsName.Replace("(Money Class", "Money");
                    clsName = clsName.Replace("First Place Processing", "FPP");
                    clsName = clsName.Replace("First Contact", "FC");
                    clsName = clsName.Replace("Qualifier", "Q");

                    if (part > 0 && EntryType != 10)
                    {
                        clsName += "Pt " + part;
                    }

                    if (dogsList.Tables[0].Rows.Count > 0)
                    {
                        /*
                        Combined 1-7 All Allsorts Agility sponsored by paws for a walk
                        Combined 6-7 Medium Agility

                            * */
                        var WrapClassDescription = clsName.Length > 45;
                        Phrase[] tmpCells = new Phrase[3];
                        tmpCells[0] = new Phrase(new Chunk(ringRow["ClsNo"].ToString(), dogInClass));
                        tmpCells[1] = new Phrase(new Chunk(clsName, dogInClass));
                        tmpCells[2] = new Phrase(new Chunk(dogsInClassDisplay, dogNotInClass ));

                        int countDogs = 0;
                        int DefaultHandler;

                        Paragraph p = new Paragraph();
                        List<Paragraph> allDogsInClass = new List<Paragraph>();
                        foreach (DataRow dogRow in dogsList.Tables[0].Rows)
                        {
                            var dogLho = Convert.ToInt32(dogRow["Lho"]);
                            int DogID = Convert.ToInt32(dogRow["DogID"]);
                            DefaultHandler = Convert.ToInt32(dogRow["DefaultHandler"]);
                            if (DefaultHandler == 0) DefaultHandler = -1;
                            if ((DefaultHandler == -1 && currentUser.UserID == UserID) ||
                                (DefaultHandler == UserID)
                                )
                            {
                                if (countDogs == 0)
                                {
                                    cell = new PdfPCell(tmpCells[0]);
                                    cell.BorderWidth = 0;
                                    cell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                                    classDetailsTable.AddCell(cell);
                                    var namePara = new Paragraph();
                                    namePara.Add(tmpCells[1]);
                                    namePara.Add(new Phrase(new Chunk(lhoInd, lhoFontBold)));
                                    p.Add(namePara);
                                }
                                if (!dogsRunningToday.Contains(DogID))
                                {
                                    dogsRunningToday.Add(DogID);
                                }
                                String dogName = dogRow["DogName"].ToString();
                                if (dogName.Length == 0)
                                {
                                    dogName = dogRow["KCName"].ToString();
                                }
                                var chunk = new Chunk("   ", dogDetailsInClass);
                                chunk.SetBackground(new Color(System.Drawing.ColorTranslator.FromHtml(dogRow["DogColour"].ToString())));

                                var dogPara = new Paragraph();
                                dogPara.Add(new Phrase(chunk));

                                if (TeamPairsManager.isMultiDog( EntryType ))
                                {
                                    pairsTeams.Add(new TeamPairsTrioDto
                                    {
                                        ClassId = ClassID,
                                        ClassNo = ClassNo,
                                        DogId = DogID,
                                        DogName = dogName,
                                        RO = -1
                                    });
                                }
                                dogPara.Add(new Phrase(new Chunk(String.Format(" [{1}] {0}", Fpp.Core.Utils.TitleCaseString(dogName), dogRow["RO"]), dogDetailsInClass)));
                                dogPara.Add(new Phrase(new Chunk(String.Format("{0}", (dogLho == 0 ? "" : " (LHO)")), font8)));
                                dogPara.Add(Chunk.NEWLINE);

                                int AltHandler = Convert.ToInt32(dogRow["AltHandler"]);
                                String HandlerName = "";
                                if (AltHandler > 0)
                                {
                                    User u = new User(AltHandler);
                                    HandlerName = u.Name;
                                    dogPara.Add(new Phrase(new Chunk(String.Format("Handler:{0}", Fpp.Core.Utils.TitleCaseString(HandlerName)), dogInClass)));
                                }
                                allDogsInClass.Add(dogPara);
                                countDogs++;
                            }
                            else
                            {
                                if (defaultUsers != null && defaultUsers.IndexOf(DefaultHandler) == -1)
                                {
                                    defaultUsers.Add(DefaultHandler);
                                }
                            }
                        }
                        if (countDogs == 0)
                        {
                            cell = new PdfPCell(new Phrase(new Chunk(ringRow["ClsNo"].ToString(), dogNotInClass)));
                            cell.BorderWidth = 0;
                            cell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                            classDetailsTable.AddCell(cell);

                            var namePara = new Paragraph();
                            namePara.Add(new Phrase(new Chunk(clsName, dogNotInClass)));
                            namePara.Add(new Phrase(new Chunk(lhoInd, lhoFontBold)));
                            p.Add(namePara);
                            cell = new PdfPCell(p);
                            cell.BorderWidth = 0;
                            cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                            cell.NoWrap = false;
                            classDetailsTable.AddCell(cell);

                            cell = new PdfPCell(new Phrase(new Chunk(dogsInClassDisplay, dogNotInClass)));
                            cell.BorderWidth = 0;
                            cell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                            classDetailsTable.AddCell(cell);
                        }
                        else
                        {

                            cell = new PdfPCell(p);
                            cell.BorderWidth = 0;
                            cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                            cell.NoWrap = false;

                            classDetailsTable.AddCell(cell);

                            cell = new PdfPCell(tmpCells[2]);
                            cell.BorderWidth = 0;
                            cell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                            classDetailsTable.AddCell(cell);

                            cell = new PdfPCell(new Phrase(new Chunk("", dogDetailsInClass)));
                            cell.BorderWidth = 0;
                            cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                            cell.NoWrap = false;
                            classDetailsTable.AddCell(cell);

                            var tbl4Dogs = new PdfPTable(1);
                            foreach (var item in allDogsInClass)
                            {
                                cell = new PdfPCell(new Phrase(item));
                                cell.BorderWidth = 0;
                                cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                                tbl4Dogs.AddCell(cell);
                            }
                            cell = new PdfPCell();
                            cell.BorderWidth = 0;
                            cell.FixedHeight = 4f;
                            tbl4Dogs.AddCell(cell);

                            cell = new PdfPCell(tbl4Dogs);
                            cell.BorderWidth = 0;
                            cell.Colspan = 2;
                            classDetailsTable.AddCell(cell);
                        }
                    }
                    else
                    {
                        cell = new PdfPCell(new Phrase(new Chunk(ringRow["ClsNo"].ToString(), dogNotInClass)));
                        cell.BorderWidth = 0;
                        cell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                        classDetailsTable.AddCell(cell);

                        var namePara = new Paragraph();
                        namePara.Add(new Phrase(new Chunk(clsName, dogNotInClass)));
                        namePara.Add(new Phrase(new Chunk(lhoInd, lhoFontBold)));
                        cell = new PdfPCell(namePara);
                        cell.BorderWidth = 0;
                        cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                        cell.NoWrap = false;
                        classDetailsTable.AddCell(cell);

                        cell = new PdfPCell(new Phrase(new Chunk(dogsInClassDisplay, dogNotInClass)));
                        cell.BorderWidth = 0;
                        cell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                        classDetailsTable.AddCell(cell);

                    }

                    PrevShowDetailsID = ShowDetailsID;
                }

                if (dogsRunningToday.Count() > 0 || UserID == -1)
                {
                    if (ringCnt % MaxColumns != 0)
                    {
                        var remind = ringCnt % MaxColumns;
                        while (remind-- > 0)
                        {
                            cell = new PdfPCell(new Phrase(new Chunk(" ", pageFont)));
                            cell.BorderWidth = 0;
                            rings.AddCell(cell);
                        }
                        doc.Add(headerPage);
                        doc.Add(rings);
                    }

                    if (UserID > -1)
                    {
                        if (currentUser.UserID != UserID)
                        {
                            User defaultHandler = new User(UserID);
                        }
                    }
                    doc.NewPage();
                    pageCount++;
                }
                else
                {
                    if (dogsRunningToday.Count() > 0)
                    {
                        if (ringCnt % MaxColumns != 0)
                        {
                            var remind = ringCnt % MaxColumns;
                            while (remind-- > 0)
                            {
                                cell = new PdfPCell(new Phrase(new Chunk(" ", pageFont)));
                                cell.BorderWidth = 0;
                                rings.AddCell(cell);
                            }
                            doc.Add(headerPage);
                            doc.Add(rings);
                        }

                        if (UserID > -1)
                        {
                            if (currentUser.UserID != UserID)
                            {
                                User defaultHandler = new User(UserID);
                            }
                        }
                        doc.NewPage();
                        pageCount++;
                    }
                }
            }
            catch (Exception e)
            {
                AppException.LogError($"Error Running Plan:{e.Message},{e.StackTrace}");
            }
        }
Пример #2
0
        /// <summary>
        /// Adds conflicts to the database depending upon the current state of the election.
        /// </summary>
        /// <param name="session">A valid session.</param>
        protected virtual void ConflictLogic(ISession session)
        {
            List<ElectionConflict> conflicts = ElectionConflict.FindElectionConflicts(session, ID);
            foreach (ElectionConflict conflict in conflicts)
                NHibernateHelper.Delete(session, conflict);

            ITransaction transaction = session.BeginTransaction();
            // Get the current committee
            Committee committee = Committee.FindCommittee(session, PertinentCommittee);

            // Get the users who won the election.
            Dictionary<string, int> winners = GetResults(session);
            List<User> winningUsers = new List<User>();
            foreach (string email in winners.Keys)
            {
                winningUsers.Add(User.FindUser(session, email));
            }

            // Get the users on the committee.
            List<User> members = User.FindUsers(session, committee.Name);

            // List all of the departments currently present on the committee.
            // and use a parallel list to store the ID of the other department
            // member so we can add it to the conflict later.
            List<DepartmentType> departments = new List<DepartmentType>();
            List<int> secID = new List<int>();
            foreach (User i in members)
            {
                departments.Add(i.Department);
                secID.Add(i.ID);
            }

            // For each user who won, add a new conflict if their department
            // is already present on the list. Adding, departments as we go.
            // Also raise conflicts if the winning users hold officer positions,
            // or if they already serve on a committee.
            foreach (User i in winningUsers)
            {
                // check if they have a prior committment
                if (i.OfficerPosition != OfficerPositionType.None ||
                    i.CurrentCommittee != User.NoCommittee)
                {
                    ElectionConflict conflict = new ElectionConflict();
                    conflict.Election = ID;
                    conflict.FirstUser = i.ID;
                    conflict.SecUser = ElectionConflict.SecondUserNotApplicable;
                    conflict.Type = ConflictType.ElectedToMultipleCommittees;
                    session.SaveOrUpdate(conflict);
                }

                // check for department-based conflicts
                if(departments.Contains(i.Department))
                {
                    ElectionConflict conflict = new ElectionConflict();
                    conflict.Election = ID;
                    conflict.FirstUser = i.ID;
                    conflict.SecUser = secID[departments.IndexOf(i.Department)];
                    conflict.Type = ConflictType.TooManyDeptMembers;
                    session.SaveOrUpdate(conflict);
                }
            }
            session.Flush();
            NHibernateHelper.Finished(transaction);
        }
Пример #3
0
        /// <summary>
        /// 输出到PDF
        /// </summary>
        /// <param name="list"></param>
        /// <param name="sysFont"></param>
        /// <param name="multiRow"></param>
        /// <param name="export">算高度的情况最后输出时使用</param>
        /// <returns></returns>
        public Table WriteFields(List<List<PdfDesc>> list, System.Drawing.Font sysFont, int multiRow, bool export)
        {
            #region Variable Definition
            Cell cell = null;
            int maxColumnCount = -1;
            int maxRowCount = -1;
            LineSeparator lineSeparator = null;
            int tempCount = 0;
            int previousFieldCells = 0;
            Table tb = null;
            #endregion

            //try
            //{
                Font pdfFont = this.GetPdfFont(sysFont);

                //Hashtable allStartIndex = new Hashtable();

                Dictionary<int, int> allStartIndex = new Dictionary<int, int>();

                if (export)
                {
                    foreach (List<PdfDesc> row in list)
                    {
                        if (!allStartIndex.ContainsKey(row[0].FieldNum))
                        {
                            allStartIndex.Add(row[0].FieldNum, list.IndexOf(row));
                        }
                    }
                }
                else
                {
                    allStartIndex.Add(0, 0);
                }

                List<int> startIndex = new List<int>();

                foreach (int index in allStartIndex.Values)
                {
                    startIndex.Add(index);
                }

                for (int l = 0; l < startIndex.Count; l++)
                {
                    //計算最大Column和最大Row

                    maxColumnCount = 0;

                    if (startIndex.Count == 1)
                    {
                        maxRowCount = list.Count;
                    }
                    else if (l != startIndex.Count - 1)
                    {
                        maxRowCount = startIndex[l + 1] - startIndex[l];
                    }
                    else
                    {
                        maxRowCount = list.Count - startIndex[l];
                    }

                    for (int s = startIndex[l]; s < list.Count; s++)
                    //foreach (List<PdfDesc> row in list)
                    {
                        if (startIndex.Count != 1)
                        {
                            if (l != startIndex.Count - 1 && s == startIndex[l + 1])
                            {
                                break;
                            }
                        }

                        List<PdfDesc> row = list[s];

                        foreach (PdfDesc pdfDesc in row)
                        {
                            tempCount += pdfDesc.Cells;
                        }

                        if (tempCount > maxColumnCount)
                        {
                            maxColumnCount = tempCount;
                        }

                        tempCount = 0;
                    }

                    tb = new Table(maxColumnCount, maxRowCount);

                    #region 計算欄位寬度
                    if (multiRow == 1)
                    {
                        int[] widths = new int[maxColumnCount];

                        previousFieldCells = 0;

                        List<PdfDesc> firstRow = list[startIndex[l]];

                        for (int i = 0; i < firstRow.Count; i++)
                        {
                            int widthPercent = Convert.ToInt32(Math.Truncate((UnitConversion.GetPdfLetterWidth(firstRow[i].Width, sysFont)
                                / Convert.ToDouble((this.pdfDoc.PageSize.Width - this.pdfDoc.LeftMargin - this.pdfDoc.RightMargin))) * 100)); //算出百分比

                            if (i == 0)
                            {
                                widths[i] = widthPercent;

                                if (firstRow[i].Cells > 1)
                                {
                                    for (int j = 0; j < firstRow[i].Cells - 1; j++)
                                    {
                                        widths[i + j + 1] = widthPercent;
                                    }
                                }
                            }
                            else
                            {
                                widths[previousFieldCells] = widthPercent;

                                if (firstRow[i].Cells > 1)
                                {
                                    for (int j = 0; j < firstRow[i].Cells - 1; j++)
                                    {
                                        widths[previousFieldCells + j + 1] = widthPercent;
                                    }
                                }
                            }

                            previousFieldCells += firstRow[i].Cells;
                        }

                        tb.SetWidths(widths);

                        previousFieldCells = 0;
                    }
                    #endregion

                    if (!this.report.Format.ColumnGridLine)
                    {
                        tb.Border = Rectangle.NO_BORDER;
                    }

                    tb.Cellpadding = PdfSizeConfig.Cellpadding;
                    //tb.Width = ((this.pdfDoc.PageSize.Width - this.pdfDoc.LeftMargin - this.pdfDoc.RightMargin) / this.pdfDoc.PageSize.Width) * 100; //此處為百分比
                    tb.Width = 100;
                    tb.Alignment = Element.ALIGN_LEFT;

                    for (int j = startIndex[l]; j < list.Count; j++)
                    {
                        if (startIndex.Count != 1)
                        {
                            if (l != startIndex.Count - 1 && j == startIndex[l + 1])
                            {
                                break;
                            }
                        }

                        List<PdfDesc> row = list[j];

                        previousFieldCells = 0;
                        for (int i = 0; i < row.Count; i++)
                        {
                            PdfDesc pdfDesc = row[i];

                            switch (pdfDesc.GroupGap)
                            {
                                case DataSourceItem.GroupGapType.None:
                                    cell = new Cell(new Chunk(pdfDesc.Value, pdfFont));
                                    cell.Colspan = pdfDesc.Cells;
                                    cell.HorizontalAlignment = this.GetPdfHAlignByStr(pdfDesc.HAlign);
                                    break;
                                case DataSourceItem.GroupGapType.EmptyRow:
                                    if (i == 0)
                                    {
                                        cell = new Cell(new Chunk(String.Empty, pdfFont));
                                        cell.Colspan = maxColumnCount;
                                    }
                                    break;
                                case DataSourceItem.GroupGapType.SingleLine:
                                    if (i == 0)
                                    {
                                        cell = new Cell();
                                        lineSeparator = new LineSeparator();
                                        lineSeparator.LineWidth = cell.Width;
                                        lineSeparator.Offset = PdfSizeConfig.LineSeparatorOffsetU;
                                        cell.AddElement(lineSeparator);
                                        cell.Colspan = tb.Columns;
                                    }
                                    break;
                                case DataSourceItem.GroupGapType.DoubleLine:
                                    if (i == 0)
                                    {
                                        cell = new Cell();
                                        lineSeparator = new LineSeparator();
                                        lineSeparator.LineWidth = cell.Width;
                                        lineSeparator.Offset = PdfSizeConfig.LineSeparatorOffsetU;
                                        cell.AddElement(lineSeparator);
                                        lineSeparator = new LineSeparator();
                                        lineSeparator.LineWidth = cell.Width;
                                        lineSeparator.Offset = PdfSizeConfig.LineSeparatorOffsetD;
                                        cell.AddElement(lineSeparator);
                                        cell.Colspan = tb.Columns;
                                    }
                                    break;
                            }

                            cell.BorderWidthLeft = pdfDesc.LeftLine == true ? PdfSizeConfig.BorderWidth : PdfSizeConfig.BorderWidthZero;
                            cell.BorderWidthRight = pdfDesc.RightLine == true ? PdfSizeConfig.BorderWidth : PdfSizeConfig.BorderWidthZero;
                            cell.BorderWidthTop = pdfDesc.TopLine == true ? PdfSizeConfig.BorderWidth : PdfSizeConfig.BorderWidthZero;
                            cell.BorderWidthBottom = pdfDesc.BottomLine == true ? PdfSizeConfig.BorderWidth : PdfSizeConfig.BorderWidthZero;

                            if (j == list.Count - 1)
                            {
                                cell.BorderWidthBottom = report.Format.RowGridLine == true ? PdfSizeConfig.BorderWidth : PdfSizeConfig.BorderWidthZero;
                            }

                            cell.UseAscender = true; //此屬性設置為True的時候VerticalAlignment才會起作用
                            cell.VerticalAlignment = Cell.ALIGN_MIDDLE;

                            switch (pdfDesc.GroupGap)
                            {
                                case DataSourceItem.GroupGapType.None:
                                    if (i == 0)
                                    {
                                        tb.AddCell(cell, j, i);
                                    }
                                    else
                                    {
                                        tb.AddCell(cell, j, previousFieldCells);
                                    }
                                    break;
                                case DataSourceItem.GroupGapType.EmptyRow:
                                case DataSourceItem.GroupGapType.SingleLine:
                                case DataSourceItem.GroupGapType.DoubleLine:
                                    if (i == 0)
                                    {
                                        tb.AddCell(cell, j, i);
                                    }
                                    break;
                            }

                            previousFieldCells += pdfDesc.Cells;
                        }
                    }

                    if (!ExportByHeight || export)
                    {
                        this.pdfDoc.Add(tb);
                    }
                }
            //}
            //catch (Exception ex)
            //{
            //    log.WriteExceptionInfo(ex);
            //    throw ex;
            //}

            return tb;
        }
Пример #4
0
        public Table WriteItem(List<List<object>> lists, System.Drawing.Font sysFont)
        {
            #region Variable Definition
            //int tempCount = 0;
            int cellCount = 0;
            int maxColumnCount = -1;
            Font pdfFont = null;
            Table tb = null;
            Image image = null;
            string imagePath = String.Empty;
            float imageWidth = float.Epsilon;
            Cell cell = null;
            double height = 0.0;
            #endregion

            //try
            //{
                pdfFont = this.GetPdfFont(sysFont);

                //计算Table中最大的Column数。
                #region Old Function
                //foreach (List<object> list in lists)
                //{
                //    foreach (ReportItem item in list)
                //    {
                //        tempCount += item.Cells;
                //    }
                //    if (tempCount > maxColumnCount)
                //    {
                //        maxColumnCount = tempCount;
                //    }
                //    tempCount = 0;
                //}
                #endregion

                maxColumnCount = mPageWidth;

                if (lists.Count == 0)
                {
                    return tb;
                }

                tb = new Table(maxColumnCount, lists.Count);
                tb.Border = Rectangle.NO_BORDER;

                tb.Cellpadding = PdfSizeConfig.Cellpadding;
                //tb.Width = ((this.pdfDoc.PageSize.Width - this.pdfDoc.LeftMargin - this.pdfDoc.RightMargin) / this.pdfDoc.PageSize.Width) * 100; //此處為百分比
                tb.Width = 100;
                tb.Alignment = Element.ALIGN_LEFT;

                foreach (List<object> list in lists)
                {
                    cellCount = 0;

                    height += GetHeight(list, sysFont);

                    for (int i = 0; i < list.Count; i++)
                    {
                        if (list[i].GetType().Name != "ReportImageItem")
                        {
                            if (((ReportItem)list[i]).Font == null)
                            {
                                pdfFont = this.GetPdfFont(sysFont);
                            }
                            else
                            {
                                pdfFont = this.GetPdfFont(((ReportItem)list[i]).Font);
                            }
                            string value = "";
                            string format = "";

                            if (string.IsNullOrEmpty(((ReportItem)list[i]).Format))
                            {
                                if (list[i] is ReportDataSourceItem)
                                {
                                    DDProvider ddProvider = new DDProvider(report.HeaderDataSource, mDesignTime);
                                    string ddValue = ddProvider.GetDDValue(((ReportDataSourceItem)list[i]).ColumnName, DDInfo.FieldCaption).ToString();
                                    if (ddValue == "")
                                    {
                                        ddValue = ddProvider.GetDDValue(((ReportDataSourceItem)list[i]).ColumnName, DDInfo.FieldName).ToString();
                                    }
                                    format = ddValue + ":{0}";
                                }
                                else
                                {
                                    format = "{0}";
                                }
                            }
                            else
                            {
                                format = ((ReportItem)list[i]).Format;
                            }

                            value = string.IsNullOrEmpty(((ReportItem)list[i]).Format) ? string.Format(format, ((ReportItem)list[i]).Value) :
                                String.Format(format, ((ReportItem)list[i]).Value);

                            cell = new Cell(new Chunk(value, pdfFont));
                        }
                        else
                        {
                            #region Image Item
                            image = Image.GetInstance((System.Drawing.Image)((ReportItem)list[i]).Value, System.Drawing.Imaging.ImageFormat.Jpeg);

                            image.Alignment = this.GetPdfImageHAlign(((ReportItem)list[i]).ContentAlignment);

                            if (list.Count > 1)
                            {
                                imageWidth = (this.pdfDoc.PageSize.Width - this.pdfDoc.LeftMargin - this.pdfDoc.RightMargin) / (float)list.Count;
                                //imageWidth -= (float)16;
                                //image.ScaleAbsoluteWidth(imageWidth);
                            }
                            Chunk chuck = new Chunk(image, 0, 0, true);
                            cell = new Cell(chuck);
                            #endregion
                        }

                        cell.UseAscender = true; //此屬性設置為True的時候VerticalAlignment才會起作用
                        cell.VerticalAlignment = Cell.ALIGN_MIDDLE;

                        cell.HorizontalAlignment = this.GetPdfHAlign(((ReportItem)list[i]).ContentAlignment);

                        if (((ReportItem)list[i]).Cells == 0)
                        {
                            if (tb.Columns - cellCount != 0)
                            {
                                cell.Colspan = tb.Columns - cellCount;
                            }
                        }
                        else
                        {
                            cell.Colspan = ((ReportItem)list[i]).Cells;
                        }
                        cell.Border = Rectangle.NO_BORDER;

                        if (((ReportItem)list[i]).Position == ReportItem.PositionAlign.Right && ((ReportItem)list[i]).Cells != 0)
                        {
                            if (maxColumnCount - cellCount - ((ReportItem)list[i]).Cells != 0)
                            {
                                Cell tempCell = new Cell();
                                tempCell.Colspan = maxColumnCount - cellCount - ((ReportItem)list[i]).Cells;
                                tempCell.Border = Rectangle.NO_BORDER;
                                tb.AddCell(tempCell);

                                cellCount = maxColumnCount - ((ReportItem)list[i]).Cells;
                            }
                        }

                        if (i == 0 && ((ReportItem)list[i]).Position != ReportItem.PositionAlign.Right)
                        {
                            tb.AddCell(cell, lists.IndexOf(list), i);
                        }
                        else
                        {
                            tb.AddCell(cell, lists.IndexOf(list), cellCount);
                        }

                        cellCount += ((ReportItem)list[i]).Cells;
                    }
                }

                if (ExportByHeight)
                {
                    if (HeaderTable == null && object.ReferenceEquals(sysFont, report.HeaderFont))
                    {
                        HeaderTable = tb;

                        if (HeaderHeight == 0.0)
                        {
                            HeaderHeight = height;
                        }

                    }
                    else if (FooterTable == null && object.ReferenceEquals(sysFont, report.FooterFont))
                    {
                        FooterTable = tb;

                        if (FooterHeight == 0.0)
                        {
                            FooterHeight = height;
                        }
                    }
                }
                else
                {
                    this.pdfDoc.Add(tb);
                }
            //}
            //catch (Exception ex)
            //{
            //    log.WriteExceptionInfo(ex);
            //    throw ex;
            //}

            return tb;
        }
        private void printRingForUser(UserShows userShow, int UserID, Document doc, ref List<int> defaultUsers, ref int pageCount)
        {
            String html = "";
            float[] ringColumns = new float[] { 300, 300, 300, 300};

            Font pageFont = FontFactory.GetFont("Arial", 22, Font.NORMAL);
            Font headerFont = new Font(Font.HELVETICA, 16, Font.BOLD, Color.BLACK);
            Font judgeFont = FontFactory.GetFont("Arial", 9, Font.BOLD);
            Font notInClassFont = new Font(Font.HELVETICA, 6, Font.NORMAL, Color.BLACK);
            Font inClassFont = new Font(Font.HELVETICA, 9, Font.NORMAL, Color.BLACK);
            Font font = new Font(Font.HELVETICA, 10, Font.NORMAL, Color.BLACK);
            Font font1 = FontFactory.GetFont("Arial", 18, Font.BOLD);
            Font dogNotInClass = new Font(Font.HELVETICA, 6, Font.NORMAL, Color.BLACK);
            Font dogInClass = new Font(Font.HELVETICA, 9, Font.NORMAL, Color.BLACK);
            Font dogDetailsInClass = new Font(Font.HELVETICA, 9, Font.BOLD, Color.BLACK);
            Fpp.WebModules.Business.User currentUser = new User(userShow.Userid);
            Shows show = new Shows(userShow.ShowID);

            List<ShowDetails> showDetailsList = ShowDetails.GetShowDaysList(userShow.ShowID);
            doc.Add(new Paragraph(show.ShowName, pageFont));

            Rings r = new Rings();
            DataSet ringList = r.GetAllRingsForShow(userShow.ShowID, "ShowDate");

            Dogs d = new Dogs();

            DogClasses dc = new DogClasses();
            DateTime dt = DateTime.Now;
            int currentRingID = 0;
            int ShowDetailsID = -1;
            int PrevShowDetailsID = -1;
            PdfPTable rings = new PdfPTable(ringColumns);

            int ringCnt = 0;
            PdfPCell cell = null;
            PdfPTable ringDetails = null;
            PdfPTable classDetailsTable = null;
            List<int> dogsRunningToday = new List<int>();
            foreach (DataRow ringRow in ringList.Tables[0].Rows)
            {
                int RingID = Convert.ToInt32(ringRow["RingID"]);
                ShowDetailsID = Convert.ToInt32(ringRow["ShowDetailsID"]);

                if (ringRow.IsNull("ClassID"))
                {
                    continue;
                }
                int ClassID = Convert.ToInt32(ringRow["ClassID"]);
                DateTime rowDT = Convert.ToDateTime(ringRow["ShowDate"]);
                if (rowDT != dt)
                {
                    if (currentRingID != 0)
                    {
                        if (ringCnt % 4 != 0)
                        {
                            var remind = ringCnt % 4;
                            while (remind-- > 0)
                            {
                                cell = new PdfPCell(new Phrase(new Chunk(" ", pageFont)));
                                cell.BorderWidth = 0;
                                rings.AddCell(cell);
                            }
                        }

                        doc.Add(rings);
                        if (currentUser.UserID == UserID)
                        {
                            doc.Add(getHandlerDetails(userShow, currentUser, PrevShowDetailsID, dogsRunningToday));
                        }
                        else
                        {
                            User defaultHandler = new User(UserID);
                            doc.Add(getHandlerDetails(userShow, defaultHandler, PrevShowDetailsID, dogsRunningToday));
                        }
                        doc.NewPage();
                        if (dogsRunningToday.Count > 0)
                        {
                            pageCount++;
                        }
                    }
                    dogsRunningToday.Clear();
                    doc.Add(new Paragraph(rowDT.ToString("dddd d MMM"), headerFont));
                    doc.Add(new Paragraph("  ", judgeFont));
                    dt = rowDT;
                    rings = new PdfPTable(ringColumns);
                    rings.WidthPercentage = 100;
                    ringCnt = 0;
                }

                if (currentRingID != RingID)
                {
                    ringCnt++;
                    ringDetails = new PdfPTable(1);
                    rings.AddCell(new PdfPCell( ringDetails));

                    List<Judge> judgeList = Judge.getJudgesForRingList(RingID);

                    cell = new PdfPCell(new Phrase(new Chunk("Ring No " + ringRow["RingNo"].ToString(), judgeFont)));
                    cell.BorderWidth = 0;
                    cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    ringDetails.AddCell(cell);

                    foreach (Judge judge in judgeList)
                    {
                        cell = new PdfPCell(new Phrase(new Chunk(judge.Name, judgeFont)));
                        cell.BorderWidth = 0;
                        cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        ringDetails.AddCell(cell);
                    }
                    currentRingID = RingID;
                    classDetailsTable = new PdfPTable(new float[] { 50, 225, 100 });
                    classDetailsTable.DefaultCell.BorderWidth = 0;
                    ringDetails.AddCell(classDetailsTable);
                }
                html += "<tr>";
                DataSet dogsList = d.GetDogsInClass(userShow.Userid, ClassID);
                int DogsInClass = d.dogsInClassCount(ClassID);

                String clsName = String.Format("{0} {1} {2} {3}",
                                ShowClasses.expandCatagory(ringRow),
                                ShowClasses.expandHeight(ringRow),
                                ringRow["LongName"],
                                ringRow["name"]);
                String grades = ShowClasses.shortenGrades(ringRow);
                int ix = clsName.IndexOf("Grd");
                if (ix == -1) ix = clsName.IndexOf("Cmb");
                if (ix > -1)
                {
                    clsName = clsName.Substring(0, ix + 3) + " " + grades + " " + clsName.Substring(ix + 4);
                }
                else
                {
                    ix = clsName.IndexOf(" ");
                    clsName = clsName.Substring(0, ix) + " " + grades + " " + clsName.Substring(ix + 1);
                }

                if (dogsList.Tables[0].Rows.Count > 0)
                {
                    Phrase[] tmpCells = new Phrase[3];
                    tmpCells[0] = new Phrase(new Chunk(ringRow["ClsNo"].ToString(), dogInClass));
                    tmpCells[1] = new Phrase(new Chunk(clsName, dogInClass));
                    tmpCells[2] = new Phrase(new Chunk(String.Format("({0})", DogsInClass), dogInClass));

                    int countDogs = 0;
                    int DefaultHandler;
                    Paragraph p = new Paragraph();
                    foreach (DataRow dogRow in dogsList.Tables[0].Rows)
                    {
                        int DogID = Convert.ToInt32(dogRow["DogID"]);
                        DefaultHandler = Convert.ToInt32(dogRow["DefaultHandler"]);
                        if (DefaultHandler == 0) DefaultHandler = -1;
                        if ((DefaultHandler == -1 && currentUser.UserID == UserID) ||
                            (DefaultHandler == UserID)
                            )
                        {
                            if (countDogs == 0)
                            {
                                cell = new PdfPCell(tmpCells[0]);
                                cell.BorderWidth = 0;
                                cell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                                classDetailsTable.AddCell(cell);
                                p.Add(tmpCells[1]);
                                p.Add(Chunk.NEWLINE);
                            }
                            if (!dogsRunningToday.Contains(DogID))
                            {
                                dogsRunningToday.Add(DogID);
                            }
                            String img = "<img src='data:image/gif;base64," + CreateImage(dogRow["DogColour"].ToString()) + "' />";
                            String dogName = dogRow["DogName"].ToString();
                            if (dogName.Length == 0)
                            {
                                dogName = dogRow["KCName"].ToString();
                            }
                            var chunk = new Chunk("   ", dogDetailsInClass);
                            chunk.SetBackground(new Color( System.Drawing.ColorTranslator.FromHtml(dogRow["DogColour"].ToString())  ));
                            p.Add(new Phrase(chunk));
                            p.Add(new Phrase(new Chunk(String.Format(" [{1}] {0}", dogName, dogRow["RO"]), dogDetailsInClass)));
                            p.Add(Chunk.NEWLINE);

                            int AltHandler = Convert.ToInt32(dogRow["AltHandler"]);
                            String HandlerName = "";
                            if (AltHandler > 0)
                            {
                                User u = new User(AltHandler);
                                HandlerName = u.Name;

                                html += "<div class='altHandler'>Handler:" + AltHandler + "</div>";
                                p.Add(Chunk.NEWLINE);
                                p.Add(new Phrase(new Chunk(String.Format("Handler:", AltHandler),dogInClass)));
                            }
                            countDogs++;
                        }
                        else
                        {
                            if (defaultUsers != null && defaultUsers.IndexOf(DefaultHandler) == -1)
                            {
                                defaultUsers.Add(DefaultHandler);
                            }
                        }
                    }
                    if (countDogs == 0)
                    {
                        cell = new PdfPCell(new Phrase(new Chunk(ringRow["ClsNo"].ToString(), dogNotInClass)));
                        cell.BorderWidth = 0;
                        cell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                        classDetailsTable.AddCell(cell);

                        cell = new PdfPCell(new Phrase(new Chunk(clsName, dogNotInClass)));
                        cell.BorderWidth = 0;
                        cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                        cell.NoWrap = true;
                        classDetailsTable.AddCell(cell);

                        cell = new PdfPCell(new Phrase(new Chunk(String.Format("({0})", DogsInClass), dogNotInClass)));
                        cell.BorderWidth = 0;
                        cell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                        classDetailsTable.AddCell(cell);
                    }
                    else
                    {

                        cell = new PdfPCell(p);
                        cell.BorderWidth = 0;
                        cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                        cell.NoWrap = true;
                        classDetailsTable.AddCell(cell);

                        cell = new PdfPCell(tmpCells[2]);
                        cell.BorderWidth = 0;
                        cell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                        classDetailsTable.AddCell(cell);
                    }
                }
                else
                {
                    cell = new PdfPCell(new Phrase(new Chunk(ringRow["ClsNo"].ToString(), dogNotInClass)));
                    cell.BorderWidth = 0;
                    cell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                    classDetailsTable.AddCell(cell);

                    cell = new PdfPCell(new Phrase(new Chunk(clsName, dogNotInClass)));
                    cell.BorderWidth = 0;
                    cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                    classDetailsTable.AddCell(cell);

                    cell = new PdfPCell(new Phrase(new Chunk(String.Format("({0})", DogsInClass), dogNotInClass)));
                    cell.BorderWidth = 0;
                    cell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                    classDetailsTable.AddCell(cell);
                }

                PrevShowDetailsID = ShowDetailsID;
            }

            if (ringCnt % 4 != 0)
            {
                var remind = ringCnt % 4;
                while (remind-- > 0)
                {
                    cell = new PdfPCell(new Phrase(new Chunk(" ", pageFont)));
                    cell.BorderWidth = 0;
                    rings.AddCell(cell);

                }
            }

            if (currentUser.UserID == UserID)
            {
                doc.Add(getHandlerDetails(userShow, currentUser, PrevShowDetailsID, dogsRunningToday));
            }
            else
            {
                User defaultHandler = new User(UserID);
                doc.Add(getHandlerDetails(userShow, defaultHandler, PrevShowDetailsID, dogsRunningToday));
            }
            doc.NewPage();
        }