";
page_control_list = this.str_page_control_template.split("");
strBuf.Append("\n" + page_control_list[0]);
strBuf.Append("\n" + page_control_list[1]);
for (var i = 1; i <= this.dt._MaxPageNumber; i++)
{
var _buf = page_control_list[2];
_buf = _buf.ReplaceAll("%PageNum%", i);
strBuf.Append("\n" + _buf);
}
strBuf.Append("\n" + page_control_list[3]);
strBuf.replace("%this.str_page_first%", this.str_page_first);
strBuf.replace("%this.str_page_up%", this.str_page_up);
strBuf.replace("%this.str_page_down%", this.str_page_down);
strBuf.replace("%this.str_page_last%", this.str_page_last);
strBuf.replace("%this.str_page_list%", this.str_page_list);
strBuf.replace("%this.str_page_size%", this.str_page_size);
strBuf.replace("%this.str_total_record%", this.str_total_record);
strBuf.replace("%TotalRecord%", this.dt.MaxRow());
strBuf.replace("%ControlName%", this.control_name);
strBuf.replace("%PageSize%", this.dt._PageSize);
return (strBuf);
}
/************************MARK******************************/
this.GetPageDataGrid = function ()
{
var i, strnum, j, rowCounter;
var strBuf = new StringBuilder();
var row, start, buf, strField, p_row;
var dt_row = 0, dt_col = 0;
var start_row = 0, end_row = 0;
var DataGrid = new Array();
var col_list = new Array();
var field_name_list = new Array();
j = 0;
rowCounter = 1;
start_row = (this.dt._PageNumber - 1) * this.dt._PageSize;
if (start_row < 0)
start_row = 0;
end_row = start_row + this.dt._PageSize;
//alert("end_row = " + end_row);
if (end_row > this.dt.MaxRow())
end_row = this.dt.MaxRow();
for (dt_col = 0; dt_col < this.dt.getFieldCount(); dt_col++)
{
var FieldName = this.dt.getFieldName(dt_col);
var _col = this.dt.SearchFieldName(FieldName);
field_name_list.push(FieldName);
col_list.push(_col);
}
if (this.strTemplate == "")
this.strTemplate = this.CreateTemplate();
if (this.strSplit == "")
this.strSplit = "";
this.strTemplate = this.strTemplate.ReplaceAll("%ControlName%", this.control_name);
DataGrid = this.strTemplate.split(this.strSplit);
row = DataGrid.length - 3;
strBuf.Append("\n" + DataGrid[0]);
start = 2;
buf = DataGrid[1];
strBuf.Append("\n" + buf);
for (dt_row = start_row; dt_row < end_row; dt_row++)
{
buf = "";
p_row = j % row;
buf = DataGrid[start + p_row];
buf = buf.ReplaceAll("%row%", dt_row);
buf = buf.ReplaceAll("%show_row%", dt_row+1);
// 雙色顯示
if (this.tr_dual_color)
{
if (dt_row % 2 == 1){
buf = buf.ReplaceAll("%class%", "class=\"" + this.tr_class2 + "\"");
buf = buf.ReplaceAll("%color%", "bgcolor=\"" + this.tr_color2 + "\"");
}else{
buf = buf.ReplaceAll("%class%", "class=\"" + this.tr_class1 + "\"");
buf = buf.ReplaceAll("%color%", "bgcolor=\"" + this.tr_color1 + "\"");}
}
else
buf = buf.ReplaceAll("%class%", "class=\"" + this.tr_class1 + "\"");
for (dt_col = 0; dt_col < this.dt.getFieldCount(); dt_col++)
{
//var FieldName = this.dt.getFieldName(dt_col);
//buf = buf.ReplaceAll("%" + FieldName + "%", this.dt.getRowValue(dt_row, FieldName));
var FieldName = field_name_list[dt_col];
var _col = col_list[dt_col];
var _value = this.dt.getRowValueByCol(dt_row, _col);
if (this.flg_auto_breakline == 1) {
try {
_value = _value.ReplaceAll("&", "&");
_value = _value.ReplaceAll("<", "<");
_value = _value.ReplaceAll(">", ">");
_value = _value.ReplaceAll("\"", """);
_value = _value.ReplaceAll("\n", " ");
}
catch (e) {}
}
if (buf.indexOf("%" + FieldName + "_Source%") != -1) {
_value += "";
buf = buf.ReplaceAll("%" + FieldName + "_Source%", _value.Left(500).ReplaceAll(" ", "\n"));
}
if (this.max_cols != -1 && _value.length > this.max_cols) {
_value = _value.Left(this.max_cols) + " ...";
}
// 使用者可自訂 before_td 函數在 oDataGrid 之前, 以客製化TD
try {buf = before_td(dt,buf,FieldName, _value);} catch(e) {};
buf = buf.ReplaceAll("%Cust_TD_" + FieldName + "%", "")
// by thomas 數字向右對齊
var fieldType = this.dt.getFieldType(dt_col);
switch (fieldType)
{
case "System.Decimal":
case "System.Integer":
case 'System.Double':
case 'System.Int32':
buf = buf.ReplaceAll("%TD_" + FieldName + "%", "align=right");
break;
default:
buf = buf.ReplaceAll("%TD_" + FieldName + "%", "");
}
// 格式化字串
var str_format = this.get_format(FieldName) ;
if (str_format != "")
{
_value = Format(_value, str_format );
}
// 使用者可自訂 before_td 函數在 oDataGrid 之前, 以客製化TD
// try {buf = before_value(dt,buf,FieldName,_value);} catch(e) {}
this.before_display_value(dt,buf,FieldName,_value);
// Grid 中可選 CheckBox
if (FieldName == "_select")
{
var element_name = "Search._select"
var element_param = ""
element_param += " onblur=\"JavaScript:%ControlName%.td_onblur(%row%, '%ColumnName%', this.value);\"";
element_param = element_param.ReplaceAll("%row%", dt_row);
element_param = element_param.ReplaceAll("%ColumnName%", FieldName);
element_param = element_param.ReplaceAll("%ControlName%", this.control_name);
element_param += " size='1' ";
element_param += " value='1' ";
var display_content = " "
display_content = display_content.ReplaceAll("%name%", element_name + "_" + (dt_row+1).toString());
display_content = display_content.ReplaceAll("%element_param%", element_param);
buf = buf.ReplaceAll("%" + FieldName + "%", display_content);
}
// Grid 中可選 radio
if (FieldName == "_radio"){
var element_name = "Search._radio"
var element_param = ""
element_param += " onblur=\"JavaScript:%ControlName%.td_onblur(%row%, '%ColumnName%', this.value);\"";
element_param += " onclick=\"JavaScript:event.cancelBubble=true;\"";
element_param = element_param.ReplaceAll("%row%", dt_row);
element_param = element_param.ReplaceAll("%ColumnName%", FieldName);
element_param = element_param.ReplaceAll("%ControlName%", this.control_name);
element_param += " size='1' ";
var radioItem=this.dt.getValue("_radio").split(",");
var display_content="";
var display_content2="";
for(var iit=0;iit"
display_content += "" + _raTitle +""
display_content = display_content.ReplaceAll("%name%", element_name + "_" + (dt_row+1).toString());
display_content = display_content.ReplaceAll("%element_param%", element_param);
display_content2 += display_content
}
buf = buf.ReplaceAll("%" + FieldName + "%", display_content2);
}
if (this.get_allow_edit(FieldName) == "1" && FieldName != "_select" && FieldName != "_radio")
{
var s_row = this.schema_dt.Search("NAME",FieldName);
var element_name = this.schema_dt.getValueByRow(s_row, "ELE_NAME");
var element_type = this.schema_dt.getValueByRow(s_row, "ELE_TYPE");
var str_not_null = dt.getValueByRow(row, "NOT_NULL");
var str_url = this.schema_dt.getValueByRow(s_row, "URL");
var str_element_list = this.schema_dt.getValueByRow(s_row, "ELE_LIST");
var display_content = ""
var element_param = "";
var form = new clsForm();
switch (element_type)
{
case "text":
display_content = form.create_textbox(s_row, element_name , element_param, this.schema_dt, dt_row+1, this.control_name, _value, FieldName);
break;
case "select":
case "checkbox":
case "radiobutton":
element_param += " onblur=\"JavaScript:%ControlName%.td_onblur(%row%, '%ColumnName%', this.value);\"";
element_param = element_param.ReplaceAll("%row%", dt_row);
element_param = element_param.ReplaceAll("%ColumnName%", FieldName);
element_param = element_param.ReplaceAll("%ControlName%", this.control_name);
element_param += " size='1' ";
element_param += " value='" + _value + "' ";
var _dt = this.schema_dt.getValueByRow(s_row , "DATA");
if (_dt == "")
{
if (element_type == "select")
{
var _dt = form.create_listbox(s_row, element_name, element_param, str_url, str_element_list, this.schema_dt, dt_row+1, this.control_name, _value, FieldName );
}
if (element_type == "checkbox")
{
var _dt = form.create_checkbox(s_row, element_name, element_param, str_url, str_element_list, this.schema_dt, dt_row+1, this.control_name, _value, FieldName );
}
if (element_type == "radiobutton")
{
var _dt = form.create_checkbox(s_row, element_name, element_param, str_url, str_element_list, this.schema_dt, dt_row+1, this.control_name, _value, FieldName );
}
this.schema_dt.setValueByRow(s_row , "DATA", _dt);
}
if (element_type == "select")
var display_content = _dt.getListBox(element_name+"_"+ (dt_row+1).toString(), element_param, "0", "1", str_not_null);
if (element_type == "checkbox")
var display_content = _dt.getCheckBox(element_name+"_"+ (dt_row+1).toString(), element_param, "0", "1", str_not_null);
if (element_type == "radiobutton")
var display_content = _dt.getRadioButton(element_name+"_"+ (dt_row+1).toString(), element_param, "0", "1", str_not_null);
break;
default:
var div_name = "display.form.FormName." + element_name + "_" + (dt_row+1).toString() ;
display_content += "";
display_content += " ";
buf = buf.ReplaceAll("%" + FieldName + "%", display_content);
continue;
break;
}
display_content += " ";
if (_value != "")
{
var t_func = function (__name, __value)
{
set_element_value(__name,__value);
};
if (this.functions == null) this.functions = new Array();
if (this.functions_1 == null) this.functions_1 = new Array();
if (this.functions_2 == null) this.functions_2 = new Array();
this.functions.push(t_func);
this.functions_1.push(element_name+ "_" + (dt_row+1).toString());
this.functions_2.push(_value);
}
buf = buf.ReplaceAll("%" + FieldName + "%", display_content);
}
else
buf = buf.ReplaceAll("%" + FieldName + "%", _value);
}
strBuf.Append("\n" + buf);
j += 1;
}
strBuf.Append("\n" + DataGrid[DataGrid.length-1]);
// 產生合計
if (this.settings.sum_list != "")
{
strBuf.Append(" ");
var sum_array = this.settings.sum_list.split(",");
for (var sum_cnt=0; sum_cnt < sum_array.length; sum_cnt++)
{
var field = sum_array[sum_cnt].split("|");
var digits = 3;
if (field.length == 3) digits = field[2];
strBuf.Append(field[0] + " " + FormatNumber(this.dt.sum(field[1]),digits) + " ");
}
}
return(strBuf);
}
this.CreateTemplate = function ()
{
var str = new StringBuilder();
var str_row = new StringBuilder();
var str_head = new StringBuilder();
var str_show_fields = "";
var str_column_name = "";
var str_column_title = "";
var i_show_fields = new Array();
if (this.settings.column_mapping.column == "")
{
var _column_list = "";
for (var col = 0; col < this.dt.getFieldCount(); col++)
{
var FieldName = this.dt.getFieldName(col);
if (_column_list == "")
_column_list = FieldName;
else
_column_list += "," + FieldName;
}
this.settings.column_mapping.column = _column_list;
}
if (this.settings.column_mapping.title == "")
this.settings.column_mapping.title = this.settings.column_mapping.column
str_column_name = this.settings.column_mapping.column.split(",");
str_column_title = this.settings.column_mapping.title.split(",");
if (str_column_name.length != str_column_title.length)
{
alert("column_name.length = " + str_column_name.length
+ "\n column_title.length = " + str_column_name.length
+ "\n the number of length is not match ..!"
);
return (false);
}
//Start Generate Head Template------------------------------------------------------
str_head.Append("\n");
str_head.Append("
");
for (var icol = 0; icol < this.columns; icol++)
{
if (this.flg_row_number == 1)
{
str_head.Append("\n
列數
");
}
if (this.flg_row_control == 1)
{
str_head.Append("\n
控制項
");
}
for (var col = 0; col < str_column_title.length; col++)
{
var _buf = new StringBuilder();
var FieldName = str_column_title[col];
var _col = this.dt.getFieldIndex(str_column_name[col]);
_buf.Append("\n
");
str.Append("\n");
//列數 部門編號 部門名稱 上層單位
str.Append(str_head.ToString()); //insert table head into template
str.Append("\n");
str.Append(str_row.ToString()); //insert row data into template
// str.Append("\n");
str.Append(str_row.ToString()); //insert row data into template
// str.Append("\n");
str.Append("\n
");
str.Append("\n
");
str.Append("\n
");
str.Append("
" );
str.Append("
");
str.Append("
");
str.Append("
");
str.Append("\n
");
return (str.ToString());
}
/************************MARK******************************/
/*******************設定分頁********************/
this.CreatePageControlTemplate = function ()
{
var strBuf = new StringBuilder();
strBuf.Append("\n