📄 table1.cs
字号:
lastTable.Title1.h = " + RowHeight + @"*lastTable.inputRow.all.length + ""pt"";
}else{
lastTable.footRow.presence = ""hidden"";
//lastTable.remarks.presence = ""hidden"";
table1.inputRow.occur.initial = ""1"";
lastTable = _table1.addInstance(1);
lastTable.title.presence = ""hidden"";
lastTable.subtitle.presence = ""hidden"";
xfa.host.pageDown();
}
");
return btnAddRow;
}
private Button CreateInsertRowButton()
{
Button btnInsertRow = CreateButton("+", 12, RowHeight / 2);
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, RowHeight / 2);
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, RowHeight / 2);
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;
rowA.{1}.rawValue = rowB.{2}.rawValue;
rowB.{3}.rawValue = temp;", 4);
script += @"
}
";
script = script.Replace("table2", Name);
btnMoveUp.Event.Click = new JavaScript(script);
return btnMoveUp;
}
private Button CreateMoveDownButton()
{
Button btnMoveDown = CreateButton("↓", 12, RowHeight / 2);
string script = @"
var rowIndex = table2.index*10+inputRow.index;
var rowCount = (table2.all.length-1)*10+table2.all.item(table2.all.length-1).inputRow.all.length;
if(rowIndex < rowCount-1)
{
currentRow = table2.all.item(Math.floor(rowIndex/10)).inputRow.all.item(rowIndex%10);
nextRow = table2.all.item(Math.floor((rowIndex+1)/10)).inputRow.all.item((rowIndex+1)%10);
swapValue( currentRow, nextRow );
}
function swapValue( rowA, rowB)
{
var temp;";
script += SetFieldValueScript(@"
temp = rowA.{0}.rawValue;
rowA.{1}.rawValue = rowB.{2}.rawValue;
rowB.{3}.rawValue = temp;", 4);
script += @"
}
";
script = script.Replace("table2", Name);
btnMoveDown.Event.Click = new JavaScript(script);
return btnMoveDown;
}
protected new Table CreateInputRow(string[] fieldnames, List<float> widths, out float paddingLeft, out float paddingRight)
{
int rows = 1;
int cols = fieldnames.Length;
Table tableinput = new Table(rows, cols + 2);
paddingLeft = 0;
for (int j = 0; j < cols; j++)
{
string[] items = fieldnames[j].Split(':');
string type = items[0];
string name = items[1];
switch (type)
{
case "T":
TextBox txtBox = CreateTextBox(name);
txtBox.Width = widths[j];
tableinput.Cells[0][j] = txtBox;
tableinput[txtBox.Name] = txtBox;
break;
case "N":
NumerictBox numBox = CreateNumerictBox(name);
numBox.Width = widths[j];
tableinput.Cells[0][j] = numBox;
tableinput[numBox.Name] = numBox;
break;
}
}
Table btnCellLeft = CreateButtonCell(CreateInsertRowButton(), CreateDeleteRowButton());
tableinput.Cells[0][cols] = btnCellLeft;
Table btnCellRight = CreateButtonCell(CreateMoveUpButton(), CreateMoveDownButton());
tableinput.Cells[0][cols + 1] = btnCellRight;
btnCellRight.CalculateSize();
paddingRight = btnCellRight.Width;
return tableinput;
}
protected new Table CreateButtonCell(Button upperbtn, Button lowerbtn)
{
Table btnCell = new Table(2, 1);
btnCell.Cells[0][0] = upperbtn;
btnCell.Cells[1][0] = lowerbtn;
return btnCell;
}
protected override Label CreateLabel(string text)
{
Label label = new Label();
label.Padding.Top = 3;
label.Padding.Bottom = 3;
label.Padding.Left = 3;
label.Padding.Right = 3;
label.Border.Width = 0.5F;
label.Text = text;
label.Font = new Font("宋体", 9);
label.TextAlign = Alignment.MiddleCenter;
return label;
}
protected override TextBox CreateTextBox(string name)
{
TextBox txtBox = new TextBox();
txtBox.Name = name;
txtBox.Width = 100;
txtBox.Height = RowHeight;
txtBox.Border.Style = BorderStyle.Solid;
txtBox.TextAlign = Alignment.MiddleCenter;
return txtBox;
}
protected override NumerictBox CreateNumerictBox(string name)
{
NumerictBox txtBox = new NumerictBox();
txtBox.Name = name;
txtBox.Width = 100;
txtBox.Height = RowHeight;
txtBox.Border.Style = BorderStyle.Solid;
txtBox.TextAlign = Alignment.MiddleCenter;
return txtBox;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -