⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 appendenttable.cs

📁 PDF文件格式解析库源代码
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using AnotherPDFLib.Forms;
using AnotherPDFLib.XFA;

namespace AnotherPDFLibTest
{
    public abstract class AppendentTable
    {
        public string Name;
        public string Title;
        public string SubTitle;
        public string Remarks;
        public int InitialRows = 7;
        public string[] ColumnCaptions;
        public string[] ColumnNumbers;
        public string[] FieldNames;
        public string[] footNames;
        public float TableWidth;

        Style center = new Style();
        Style right = new Style();

        public AppendentTable()
        {
            center.Alignment = Alignment.Center;
            right.Alignment = Alignment.Right;
        }

        public Form BuildForm(Page page)
        {
            Form form = new Form();
            form.Name = Name;
            form.Location = page.ContentArea.Location;
            form.Size = page.ContentArea.Size;
            form.Occurance.Inintial = 1;
            @break pageBreak = new @break();
            pageBreak.startNew = true;
            //pageBreak.before = breakTarget.pageArea;
            //pageBreak.beforeTarget = "#Page1";
            //if (Name != "table1")
            //{
            //    form.Break = pageBreak;
            //}
            pageBreak.after = breakTarget.pageArea;
            pageBreak.afterTarget = "#LandscapePage";
            if (Name != "table6")
            {
                form.Break = pageBreak;
            }
            TableWidth = form.Width * 0.85F;

            Label title = CreateTitle();
            form.ApplyStyle(center, title);
            form.Controls.Add(title);
            float titlebottom = title.Bottom;
            if (SubTitle != null)
            {
                Label subtitle = CreateSubTitle();
                subtitle.Top = title.Bottom;
                form.ApplyStyle(center, subtitle);
                form.Controls.Add(subtitle);
                titlebottom = subtitle.Bottom;
            }

            Button btnAddRow = CreateAddRowButton();
            btnAddRow.Left = 30;
            btnAddRow.Top = titlebottom;
            form.Controls.Add(btnAddRow);
            //if (Name == "table3")
            //{
            //    form.Controls.Add(btnAddRow);
            //}

            Label moneyunit = MoneyUnitLabel();
            moneyunit.Bottom = btnAddRow.Bottom;
            form.ApplyStyle(right, moneyunit);
            form.Controls.Add(moneyunit);

            Form growingtable = new Form();
            growingtable.Layout = Layout.Flow;
            growingtable.Growable = true;
            growingtable.Top = btnAddRow.Bottom + 8;

            Table[] tables = BuildTable();
            foreach (Table table in tables)
            {
                table.CalculateSize();
                growingtable.Controls.Add(table);
                growingtable.Width = Math.Max(growingtable.Width, table.Width);
            }
            form.ApplyStyle(center, growingtable);
            form.Controls.Add(growingtable);
            btnAddRow.Left = growingtable.Left + growingtable.Width * 0.04F;
            moneyunit.Right = growingtable.Right * 0.96F;

            Form[] forms = BuildSubform();
            if (forms != null)
            {
                foreach (Form subform in forms)
                {
                    growingtable.Controls.Add(subform);
                }
            }

            Form remarks = CreateRemarks();
            growingtable.Controls.Add(remarks);

            //form.Variables.Add(new Variable("RowCount", InitialRows));
            return form;
        }

        private Label CreateTitle()
        {
            Label title = new Label();
            title.Text = Title;
            title.Font = new Font("隶书", 18, FontStyle.Bold);
            title.TextAlign = Alignment.Center;
            title.Name = "title";
            return title;
        }

        private Label CreateSubTitle()
        {
            Label subtitle = new Label();
            subtitle.Text = SubTitle;
            subtitle.Font = new Font("楷体_GB2312", 9);
            subtitle.TextAlign = Alignment.Center;
            subtitle.Name = "subtitle";
            return subtitle;
        }

        private Label MoneyUnitLabel()
        {
            Label moneyunit = new Label();
            moneyunit.Text = "金额单位:千元";
            moneyunit.Font = new Font("仿宋_GB2312", 12);
            return moneyunit;
        }

        protected virtual Button CreateAddRowButton()
        {
            Button btnAddRow = CreateButton("增加行", 42, 16);
            btnAddRow.Name = "btnAddRow";
            btnAddRow.Event.Click = new JavaScript(@"
var lastTable = table2.all.item(table2.all.length-1);
if(lastTable.inputRow.all.length < 10){
    lastTable.inputRow.instanceManager.addInstance(1);
}else{
    lastTable.footRow.presence = ""hidden"";
    //lastTable.remarks.presence = ""hidden"";
    table2.inputRow.occur.initial = ""1"";
    lastTable = _table2.addInstance(1);
    lastTable.title.presence = ""hidden"";
    lastTable.subtitle.presence = ""hidden"";
    xfa.host.pageDown();
}
".Replace("table2", Name));
            return btnAddRow;
        }

        private Button CreateInsertRowButton()
        {
            Button btnInsertRow = CreateButton("+", 12, 12);
            string script = @"
var lastTable = table2.all.item(table2.all.length-1);
if(lastTable.inputRow.all.length < 10){
    lastTable.inputRow.instanceManager.addInstance(1);
}else{
    lastTable.footRow.presence = ""hidden"";
    //lastTable.remarks.presence = ""hidden"";
    table2.inputRow.occur.initial = ""1"";
    lastTable = _table2.addInstance(1);
    lastTable.title.presence = ""hidden"";
    lastTable.subtitle.presence = ""hidden"";
}

var insertRowIndex = table2.index*10+inputRow.index;

var RowIndex = 0;
for(var tableIndex =0; tableIndex<table2.all.length;tableIndex++)
{
	RowIndex += table2.all.item(tableIndex).inputRow.all.length;
}
RowIndex--;

var previousRow,currentRow;

while(RowIndex>insertRowIndex)
{
	currentRow = table2.all.item(Math.floor(RowIndex/10)).inputRow.all.item(RowIndex%10);
	previousRow = table2.all.item(Math.floor((RowIndex-1)/10)).inputRow.all.item((RowIndex-1)%10);
";
            script += SetFieldValueScript("\tcurrentRow.{0}.rawValue = previousRow.{1}.rawValue;\r\n", 2);
            script += @"
	RowIndex--;
}
";
            script += ClearFieldValueScript("inputRow.{0}.rawValue = \"\";\r\n");
            script += @"
inputRow.applyNum.rawValue = ""0"";
";
            script = script.Replace("table2", Name);
            btnInsertRow.Event.Click = new JavaScript(script);
            return btnInsertRow;
        }

        private Button CreateDeleteRowButton()
        {
            Button btnDeleteRow = CreateButton("-", 12, 12);
            string script = @"
var deleteRowIndex = table2.index*10+inputRow.index;

var RowIndex = 0;
for(var tableIndex =0; tableIndex<table2.all.length;tableIndex++)
{
	RowIndex += table2.all.item(tableIndex).inputRow.all.length;
}
RowIndex--;

var previousRow,nextRow;

while(deleteRowIndex<RowIndex)
{
	currentRow = table2.all.item(Math.floor(deleteRowIndex/10)).inputRow.all.item(deleteRowIndex%10);
	nextRow = table2.all.item(Math.floor((deleteRowIndex+1)/10)).inputRow.all.item((deleteRowIndex+1)%10);
";
            script += SetFieldValueScript("\tcurrentRow.{0}.rawValue = nextRow.{1}.rawValue;\r\n", 2);
            script += @"
	deleteRowIndex++;
}

var lastTableIndex = Math.floor(deleteRowIndex/10);
var lastTable = table2.all.item(lastTableIndex);
var remainedRows = lastTable.inputRow.all.length;
if(remainedRows == 1 && lastTableIndex > 0){
	table2.all.item(lastTableIndex-1).footRow.presence = ""visible"";
	//table2.all.item(lastTableIndex-1).remarks.presence = ""visible"";
	table2.instanceManager.removeInstance(lastTableIndex);
}else{
	lastTable.inputRow.instanceManager.removeInstance(deleteRowIndex%10);
}
";
            script = script.Replace("table2", Name);
            btnDeleteRow.Event.Click = new JavaScript(script);
            return btnDeleteRow;
        }


        private Button CreateMoveUpButton()
        {
            Button btnMoveUp = CreateButton("↑", 12, 12);
            string script = @"
var rowIndex = table2.index*10+inputRow.index;

if(rowIndex > 0)
{
	currentRow = table2.all.item(Math.floor(rowIndex/10)).inputRow.all.item(rowIndex%10);
	previousRow = table2.all.item(Math.floor((rowIndex-1)/10)).inputRow.all.item((rowIndex-1)%10);
	swapValue( currentRow, previousRow );
}

function swapValue( rowA, rowB)
{
    var temp;";
            script += SetFieldValueScript(@"
	temp = rowA.{0}.rawValue;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -