Exemplo n.º 1
0
        public TableLines(string s, int st) : base(st)
        {
            string[] array = s.Split(new string[] { "\r\n" }, System.StringSplitOptions.RemoveEmptyEntries);
            array[1] = array[1].Replace(" ", "");
            string[] a = array[1].Split('|');
            int      y = array.Length, x = a.Length - 2;

            loc = new bool?[a.Length - 2];
            for (int i = 1; i < a.Length - 1; i++)
            {
                if (a[i][0] == ':' && a[i][a[i].Length - 1] == ':')
                {
                    loc[i - 1] = null;
                }
                else
                {
                    if (a[i][0] == ':')
                    {
                        loc[i - 1] = false;
                    }
                    else
                    {
                        if (a[i][a[i].Length - 1] == ':')
                        {
                            loc[i - 1] = true;
                        }
                        else
                        {
                            loc[i - 1] = false;
                        }
                    }
                }
            }
            SimpleLines[,] inLine = new SimpleLines[y - 1, x];
            for (int i = 0, k = 0; i < y; i++, k++)
            {
                if (i == 1)
                {
                    k--; continue;
                }
                string[] s_array = array[i].Split('|');
                for (int j = 1; j < x + 1; j++)
                {
                    inLine[k, j - 1] = new SimpleLines(s_array[j], st);
                }
            }
            y--;
            cell  = inLine;
            value = new TableLinesControl(inLine, loc, x, y);
            xc    = x;
            yc    = y;
        }
Exemplo n.º 2
0
        public static void Create(List <LinesText> value, Form1 parent, string str)
        {
            PdfWriter   writer   = new PdfWriter(str);
            PdfDocument pdf      = new PdfDocument(writer);
            Document    document = new Document(pdf);

            for (int i = 0; i < value.Count; i++)
            {
                if (value[i].GetType() == typeof(SimpleLines))
                {
                    SimpleLines simpleLines = value[i] as SimpleLines;
                    Paragraph   header      = new Paragraph();
                    int         y           = 5;
                    for (int j = 0; j < simpleLines.value.Controls.Count; j++)
                    {
                        if (y < simpleLines.value.Controls[j].Location.Y)
                        {
                            y = simpleLines.value.Controls[j].Location.Y;
                            header.Add("\r\n");
                        }
                        if (simpleLines.value.Controls[j].GetType() == typeof(SimpleInLineText.SimpleInLineTextControl))
                        {
                            SimpleInLineText.SimpleInLineTextControl control = simpleLines.value.Controls[j] as SimpleInLineText.SimpleInLineTextControl;
                            CreateText(control, header);
                        }
                        else
                        {
                            if (simpleLines.value.Controls[j].GetType() == typeof(Link.LinkControl))
                            {
                                Link.LinkControl control = simpleLines.value.Controls[j] as Link.LinkControl;
                                CreateLink(document, control, header, false);
                            }
                            else
                            {
                                if (simpleLines.value.Controls[j].GetType() == typeof(ImageText.ImageTextControl))
                                {
                                    CreateImage(document, simpleLines.value.Controls[j] as ImageText.ImageTextControl, false, ref header, false, true);
                                }
                                else
                                {
                                    if (simpleLines.value.Controls[j].GetType() == typeof(Label))
                                    {
                                        CreateCode(simpleLines.value.Controls[j] as Label, header);
                                    }
                                }
                            }
                        }
                    }
                    document.Add(header);
                }
                else
                {
                    if (value[i].GetType() == typeof(HeaderLines))
                    {
                        HeaderLines simpleLines = value[i] as HeaderLines;
                        Paragraph   header      = new Paragraph();
                        int         y           = 5;
                        for (int j = 0; j < simpleLines.value.Controls.Count; j++)
                        {
                            if (y < simpleLines.value.Controls[j].Location.Y)
                            {
                                y = simpleLines.value.Controls[j].Location.Y;
                                header.Add("\r\n");
                            }
                            if (simpleLines.value.Controls[j].GetType() == typeof(SimpleInLineText.SimpleInLineTextControl))
                            {
                                SimpleInLineText.SimpleInLineTextControl control = simpleLines.value.Controls[j] as SimpleInLineText.SimpleInLineTextControl;
                                CreateText(control, header);
                            }
                            else
                            {
                                if (simpleLines.value.Controls[j].GetType() == typeof(Link.LinkControl))
                                {
                                    Link.LinkControl control = simpleLines.value.Controls[j] as Link.LinkControl;
                                    CreateLink(document, control, header, false);
                                }
                                else
                                {
                                    if (simpleLines.value.Controls[j].GetType() == typeof(ImageText.ImageTextControl))
                                    {
                                        CreateImage(document, simpleLines.value.Controls[j] as ImageText.ImageTextControl, false, ref header, false, true);
                                    }
                                    else
                                    {
                                        if (simpleLines.value.Controls[j].GetType() == typeof(Label))
                                        {
                                            CreateCode(simpleLines.value.Controls[j] as Label, header);
                                        }
                                    }
                                }
                            }
                        }
                        document.Add(header);
                    }
                    else
                    {
                        if (value[i].GetType() == typeof(QuotationLines))
                        {
                            QuotationLines quotationLines = value[i] as QuotationLines;
                            Paragraph      header         = new Paragraph();
                            int            y = 5;
                            header.SetBorderLeft(new SolidBorder(ColorConstants.GRAY, 4));
                            header.SetPadding(30);
                            for (int j = 0; j < quotationLines.value.Controls.Count; j++)
                            {
                                if (y < quotationLines.value.Controls[j].Location.Y)
                                {
                                    y = quotationLines.value.Controls[j].Location.Y;
                                    header.Add("\r\n");
                                }
                                if (quotationLines.value.Controls[j].GetType() == typeof(SimpleInLineText.SimpleInLineTextControl))
                                {
                                    SimpleInLineText.SimpleInLineTextControl control = quotationLines.value.Controls[j] as SimpleInLineText.SimpleInLineTextControl;
                                    CreateText(control, header);
                                }
                                else
                                {
                                    if (quotationLines.value.Controls[j].GetType() == typeof(Link.LinkControl))
                                    {
                                        Link.LinkControl control = quotationLines.value.Controls[j] as Link.LinkControl;
                                        CreateLink(document, control, header, true);
                                    }
                                    else
                                    {
                                        if (quotationLines.value.Controls[j].GetType() == typeof(ImageText.ImageTextControl))
                                        {
                                            CreateImage(document, quotationLines.value.Controls[j] as ImageText.ImageTextControl, false, ref header, true, j + 1 == quotationLines.value.Controls.Count);
                                        }
                                        else
                                        {
                                            if (quotationLines.value.Controls[j].GetType() == typeof(Label))
                                            {
                                                CreateCode(quotationLines.value.Controls[j] as Label, header);
                                            }
                                        }
                                    }
                                }
                            }
                            document.Add(header);
                        }
                        else
                        {
                            if (value[i].GetType() == typeof(ListLine))
                            {
                                ListLine listLine = value[i] as ListLine;
                                int      n        = 0;
                                List     list     = GetList(listLine.space, listLine.value as ListLine.ListLineControl, ref n);
                                document.Add(list);
                            }
                            else
                            {
                                if (value[i].GetType() == typeof(LineLines))
                                {
                                    LineSeparator ls = new LineSeparator(new SolidLine((value[i] as LineLines).w / 2));
                                    document.Add(ls);
                                    document.Add(new Paragraph());
                                }
                                else
                                {
                                    if (value[i].GetType() == typeof(LineCode))
                                    {
                                        LineCode  lineCode = value[i] as LineCode;
                                        Paragraph header   = new Paragraph();
                                        header.SetBackgroundColor(ColorConstants.LIGHT_GRAY);
                                        int y = 5;
                                        for (int j = 0; j < lineCode.value.Controls.Count; j += 2)
                                        {
                                            if (y < lineCode.value.Controls[j].Location.Y)
                                            {
                                                y = lineCode.value.Controls[j].Location.Y;
                                                header.Add("\r\n");
                                            }
                                            if (lineCode.value.Controls[j].GetType() == typeof(Label))
                                            {
                                                int count = 4 - (lineCode.value.Controls[j + 1] as Label).Text.Length;
                                                CreateCode(lineCode.value.Controls[j + 1] as Label, header);
                                                string s = " ";
                                                for (int k = 0; k < count; k++)
                                                {
                                                    s += "  ";
                                                }
                                                header.Add(s);
                                                CreateCode(lineCode.value.Controls[j] as Label, header);
                                            }
                                        }
                                        document.Add(header);
                                    }
                                    else
                                    {
                                        if (value[i].GetType() == typeof(ChekLine))
                                        {
                                            int       y        = 5;
                                            ChekLine  chek     = value[i] as ChekLine;
                                            CheckBox  chrckbox = chek.value.Controls[0] as CheckBox;
                                            Paragraph header   = new Paragraph();
                                            if (chrckbox.Checked)
                                            {
                                                header.SetLineThrough();
                                            }
                                            if (chrckbox.Checked)
                                            {
                                                header.SetItalic();
                                            }
                                            header.Add("•     ");

                                            for (int j = 1; j < chek.value.Controls.Count; j++)
                                            {
                                                if (y < chek.value.Controls[j].Location.Y)
                                                {
                                                    y = chek.value.Controls[j].Location.Y;
                                                    header.Add("\r\n");
                                                }
                                                if (chek.value.Controls[j].GetType() == typeof(SimpleInLineText.SimpleInLineTextControl))
                                                {
                                                    SimpleInLineText.SimpleInLineTextControl control = chek.value.Controls[j] as SimpleInLineText.SimpleInLineTextControl;
                                                    CreateText(control, header);
                                                }
                                                else
                                                {
                                                    if (chek.value.Controls[j].GetType() == typeof(Link.LinkControl))
                                                    {
                                                        Link.LinkControl control = chek.value.Controls[j] as Link.LinkControl;
                                                        CreateLink(document, control, header, false);
                                                    }
                                                    else
                                                    {
                                                        if (chek.value.Controls[j].GetType() == typeof(ImageText.ImageTextControl))
                                                        {
                                                            CreateImage(document, chek.value.Controls[j] as ImageText.ImageTextControl, false, ref header, false, true);
                                                        }
                                                        else
                                                        {
                                                            if (chek.value.Controls[j].GetType() == typeof(Label))
                                                            {
                                                                CreateCode(chek.value.Controls[j] as Label, header);
                                                            }
                                                        }
                                                    }
                                                }
                                            }

                                            document.Add(header);
                                        }
                                        else
                                        {
                                            if (value[i].GetType() == typeof(TableLines))
                                            {
                                                TableLines tablelines = value[i] as TableLines;
                                                Table      table      = new Table(tablelines.xc, false);
                                                for (int j = 0; j < tablelines.yc; j++)
                                                {
                                                    for (int k = 0; k < tablelines.xc; k++)
                                                    {
                                                        Cell cell = new Cell();
                                                        if (tablelines.loc[k] == null)
                                                        {
                                                            cell.SetTextAlignment(TextAlignment.CENTER);
                                                        }
                                                        else if (tablelines.loc[k] == true)
                                                        {
                                                            cell.SetTextAlignment(TextAlignment.RIGHT);
                                                        }
                                                        else
                                                        {
                                                            cell.SetTextAlignment(TextAlignment.LEFT);
                                                        }
                                                        int         y           = 5;
                                                        Paragraph   header      = new Paragraph();
                                                        Style       style       = new Style();
                                                        SimpleLines simpleLines = tablelines.cell[j, k];
                                                        for (int a = 0; a < simpleLines.value.Controls.Count; a++)
                                                        {
                                                            if (y < simpleLines.value.Controls[a].Location.Y)
                                                            {
                                                                y = simpleLines.value.Controls[a].Location.Y;
                                                                header.Add("\r\n");
                                                            }
                                                            if (simpleLines.value.Controls[a].GetType() == typeof(SimpleInLineText.SimpleInLineTextControl))
                                                            {
                                                                SimpleInLineText.SimpleInLineTextControl control = simpleLines.value.Controls[a] as SimpleInLineText.SimpleInLineTextControl;
                                                                CreateText(control, header);
                                                            }
                                                            else
                                                            {
                                                                if (simpleLines.value.Controls[a].GetType() == typeof(Link.LinkControl))
                                                                {
                                                                    Link.LinkControl control = simpleLines.value.Controls[a] as Link.LinkControl;
                                                                    CreateLink(cell, control, header, false);
                                                                }
                                                                else
                                                                {
                                                                    if (simpleLines.value.Controls[a].GetType() == typeof(ImageText.ImageTextControl))
                                                                    {
                                                                        CreateImage(cell, simpleLines.value.Controls[a] as ImageText.ImageTextControl, false, ref header, false, true);
                                                                    }
                                                                    else
                                                                    {
                                                                        if (simpleLines.value.Controls[a].GetType() == typeof(Label))
                                                                        {
                                                                            CreateCode(simpleLines.value.Controls[a] as Label, header);
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        cell.Add(header);
                                                        table.AddCell(cell);
                                                    }
                                                }
                                                document.Add(table);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                parent.toolStripProgressBar1.Value = (int)(((float)i / value.Count) * 100);
                parent.toolStripProgressBar1.Invalidate();
            }
            document.Close();
            parent.toolStripProgressBar1.Value = 0;
            MessageBox.Show("Экспорт в pdf завершен", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }