第七章 业务数据库的管理(八)-- 打印表格行
2012-09-19 09:35
351 查看
7.6 定义要打印的表格
7.6.2 选择打印表格要用到的业务数据字段
在上一小节的定义打印表格页点击“设置表格行”按钮后将以打印表格编号为参数转到选择业务数据字段页面PrintedFields.aspx页面,选择业务数据字段,保存到PrintedTable表中。如图7.10所示:
图7.10 选择业务数据表字段
PrintedFields.aspx页面代码比较简单,主要是一个空的服务器端表格控件,表格的行和列由后台代码动态生成:
......
<form id="Form1" method="post" runat="server">
<table height="80" cellSpacing="0" cellPadding="0" width="100%" border="0">
<tr>
<td><a href="javascript:history.back()">返回上一页</a></td>
</tr>
<tr height="60"><td></td></tr>
</table>
<table cellSpacing="0" cellPadding="0" width="100%" align="center" border="0">
<tr><td style="FONT-SIZE: 16px" align="center">选择要打印的字段</td></tr>
<tr height="50"><td align="right"> </td></tr>
<tr><td><asp:table id="Tbl" style="BORDER-RIGHT: 1px solid; BORDER-TOP: 1px solid;
BORDER-LEFT: 1px solid; BORDER-BOTTOM: 1px solid; FONT-FAMILY: 宋体;
BORDER-COLLAPSE: collapse" runat="server" border="1"
cellPadding="3" cellSpacing="0" Width="100%">
</asp:table></td>
</tr>
</table>
<table height="100" cellSpacing="0" cellPadding="0" width="100%" border="0">
<tr><td vAlign="middle" align="right"> </td>
<td align="center">
<asp:Button id="Button2" runat="server" Text="继续"></asp:Button>
<asp:button id="Button1" runat="server" Text="暂时保存"></asp:button>
<asp:Button id="Button3" runat="server" Text="放弃"></asp:Button>
<asp:Label id="Label1" runat="server" ForeColor="Red"></asp:Label>
</td>
</tr>
</table>
</form>
......
PrintedFields.aspx.cs代码如下:
......
using DataAccess;
using CommonTools;
namespace workflow.admin.PrintedTable
{
public class PrintedFields : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Table Tbl;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Button Button3;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
if(! IsPostBack)
{
//验证用户是否登录
if(Session["userid"] == null)
Response.Redirect("../Message.aspx");
//使用页面状态变量保存接收的打印表格编号参数
ViewState["printedtableid"]=Request.QueryString["id"].ToString();
}
//根据printedtableid获得关联的数据表名称,因为表名为"ower.tablename",所以要分割出
//表的所有者和表名.
string printedtableid=ViewState["printedtableid"].ToString();
string strSql="select RelatedTable from PrintedTable where
PrintedTableID="+printedtableid;
Base basecode=new Base();
DataSet ds=basecode.SQLExeDataSet(strSql);
if(ds.Tables[0].Rows[0]["RelatedTable"]==DBNull.Value
|| ds.Tables[0].Rows[0]["RelatedTable"].ToString()=="")
{
Response.Write("You have encounter an error,please contact to the developer.");
return;
}
string[] owertblname=new Tools()
.StringSplit(ds.Tables[0].Rows[0]["RelatedTable"].ToString(),".");
string ower=owertblname[0];
string tablename=owertblname[1];
//根据关联表获得关联表的字段名及其中文描述.
strSql="select * from RelatedTablesFields where TableName='"+tablename+"' and
TableOwer='"+ower+"'";
ds=basecode.SQLExeDataSet(strSql);
ViewState["relatedfields"]=ds;
//根据业务表字段动态生成单选框字段选择控件
TableRow tr=new TableRow();
TableCell tc=new TableCell();
tc.Text="请选择要打印的字段:";
tc.Font.Size=FontUnit.Parse("14px");
tc.ColumnSpan=9;//一行9列
tc.HorizontalAlign=HorizontalAlign.Left;
tr.Cells.Add(tc);
Tbl.Rows.Add(tr);
tr=new TableRow();//新行
tc=new TableCell();//空白列
tr.Cells.Add(tc);
//为每一个关联字段设置单选框,并将字段名作为它的ID.
CheckBox chk=null;
Label lb=null;
for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{
//一行9列,两边空白列,中间包括7个字段选择控件
if((i% 7) == 0 & i>0)
{
//一行尾部加一列
tc=new TableCell();
tc.Text=" ";
tr.Cells.Add(tc);
//另起一行并加一列空白列
Tbl.Rows.Add(tr);
tr=new TableRow();
tc=new TableCell();
tr.Cells.Add(tc);
}
tc=new TableCell();
tc.HorizontalAlign=HorizontalAlign.Right;
lb=new Label();
lb.Text=ds.Tables[0].Rows[i]["FieldAlias"].ToString();
tc.Controls.Add(lb);
chk=new CheckBox();
chk.ID=ds.Tables[0].Rows[i]["FieldName"].ToString();//为避免出现ID重复错误
//如果是标识字段则默认不钩选并不可编辑.
if(ds.Tables[0].Rows[i]["IsIdentity"].ToString() =="Y")
{
chk.Checked=false;
chk.Enabled=false;
}
tc.Controls.Add(chk);
tr.Cells.Add(tc);
}
//最后一行最后一个空白列的跨度设置为最大值.
tc=new TableCell();
tc.ColumnSpan=9;
tr.Cells.Add(tc);
Tbl.Rows.Add(tr);
//如果PrintedTable已有打印字段的内容(即编辑已有PrintedTable记录的情形),要分割以逗
//号隔开的字段集字符串,得到字段名并设置对应控件的钩选.
strSql="select RelatedFields from PrintedTable where
PrintedTableID="+printedtableid;
ds=basecode.SQLExeDataSet(strSql);
if(ds !=null & ds.Tables[0].Rows[0]["RelatedFields"] !=DBNull.Value)
{
string printedfieldsstr="";
printedfieldsstr=ds.Tables[0].Rows[0]["RelatedFields"].ToString().Trim();
if(printedfieldsstr != "")
{
string[] fieldsarray=new Tools().StringSplit(printedfieldsstr,",");
for(int j=0;j<fieldsarray.Length;j++)
{
//由于保存字段名字符串时最后还多一个",",使得字符串数组多一行空白字串,
//所以要判断.也可以将循环条件设置为j<fieldsarray.Length-1
if(fieldsarray[j] !="")
{
chk=(CheckBox)this.FindControl(fieldsarray[j]);
if(chk !=null)//避免找不到指定的控件
chk.Checked=true;
}
}
}
}
}//Page_Load()
//保存按钮
private void Button1_Click(object sender, System.EventArgs e)
{
SaveFields();
Response.Redirect("PrintedTable.aspx");
}
//放弃按钮
private void Button3_Click(object sender, System.EventArgs e)
{
Response.Redirect("PrintedTable.aspx");
}
//继续按钮(转到设置打印表格行页面,设计表格行)
private void Button2_Click(object sender, System.EventArgs e)
{
SaveFields();
Response.Redirect("PrintedRows.aspx?id="+ViewState["printedtableid"].ToString());
}
//保存打印字段
private void SaveFields()
{
//获取字段单选框列表的值
string printedtableid=ViewState["printedtableid"].ToString();
string chkedfields="";
//CheckBox chk=null;
DataSet ds=(DataSet)ViewState["relatedfields"];
for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{
CheckBox chk=(CheckBox)this.FindControl(ds.Tables[0]
.Rows[i]["FieldName"].ToString());
if(chk.Checked)
chkedfields=chkedfields+ds.Tables[0].Rows[i]["FieldName"].ToString()+",";
}
string strSql="update PrintedTable set RelatedFields='"+chkedfields+"' where
PrintedTableID="+printedtableid;
Base basecode=new Base();
if(! basecode.SQLExeNonQuery(strSql))
{
Label1.Text=basecode.BaseSqlErrDes;
return;
}
}
}
}
7.6.2 选择打印表格要用到的业务数据字段
在上一小节的定义打印表格页点击“设置表格行”按钮后将以打印表格编号为参数转到选择业务数据字段页面PrintedFields.aspx页面,选择业务数据字段,保存到PrintedTable表中。如图7.10所示:
图7.10 选择业务数据表字段
PrintedFields.aspx页面代码比较简单,主要是一个空的服务器端表格控件,表格的行和列由后台代码动态生成:
......
<form id="Form1" method="post" runat="server">
<table height="80" cellSpacing="0" cellPadding="0" width="100%" border="0">
<tr>
<td><a href="javascript:history.back()">返回上一页</a></td>
</tr>
<tr height="60"><td></td></tr>
</table>
<table cellSpacing="0" cellPadding="0" width="100%" align="center" border="0">
<tr><td style="FONT-SIZE: 16px" align="center">选择要打印的字段</td></tr>
<tr height="50"><td align="right"> </td></tr>
<tr><td><asp:table id="Tbl" style="BORDER-RIGHT: 1px solid; BORDER-TOP: 1px solid;
BORDER-LEFT: 1px solid; BORDER-BOTTOM: 1px solid; FONT-FAMILY: 宋体;
BORDER-COLLAPSE: collapse" runat="server" border="1"
cellPadding="3" cellSpacing="0" Width="100%">
</asp:table></td>
</tr>
</table>
<table height="100" cellSpacing="0" cellPadding="0" width="100%" border="0">
<tr><td vAlign="middle" align="right"> </td>
<td align="center">
<asp:Button id="Button2" runat="server" Text="继续"></asp:Button>
<asp:button id="Button1" runat="server" Text="暂时保存"></asp:button>
<asp:Button id="Button3" runat="server" Text="放弃"></asp:Button>
<asp:Label id="Label1" runat="server" ForeColor="Red"></asp:Label>
</td>
</tr>
</table>
</form>
......
PrintedFields.aspx.cs代码如下:
......
using DataAccess;
using CommonTools;
namespace workflow.admin.PrintedTable
{
public class PrintedFields : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Table Tbl;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Button Button3;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
if(! IsPostBack)
{
//验证用户是否登录
if(Session["userid"] == null)
Response.Redirect("../Message.aspx");
//使用页面状态变量保存接收的打印表格编号参数
ViewState["printedtableid"]=Request.QueryString["id"].ToString();
}
//根据printedtableid获得关联的数据表名称,因为表名为"ower.tablename",所以要分割出
//表的所有者和表名.
string printedtableid=ViewState["printedtableid"].ToString();
string strSql="select RelatedTable from PrintedTable where
PrintedTableID="+printedtableid;
Base basecode=new Base();
DataSet ds=basecode.SQLExeDataSet(strSql);
if(ds.Tables[0].Rows[0]["RelatedTable"]==DBNull.Value
|| ds.Tables[0].Rows[0]["RelatedTable"].ToString()=="")
{
Response.Write("You have encounter an error,please contact to the developer.");
return;
}
string[] owertblname=new Tools()
.StringSplit(ds.Tables[0].Rows[0]["RelatedTable"].ToString(),".");
string ower=owertblname[0];
string tablename=owertblname[1];
//根据关联表获得关联表的字段名及其中文描述.
strSql="select * from RelatedTablesFields where TableName='"+tablename+"' and
TableOwer='"+ower+"'";
ds=basecode.SQLExeDataSet(strSql);
ViewState["relatedfields"]=ds;
//根据业务表字段动态生成单选框字段选择控件
TableRow tr=new TableRow();
TableCell tc=new TableCell();
tc.Text="请选择要打印的字段:";
tc.Font.Size=FontUnit.Parse("14px");
tc.ColumnSpan=9;//一行9列
tc.HorizontalAlign=HorizontalAlign.Left;
tr.Cells.Add(tc);
Tbl.Rows.Add(tr);
tr=new TableRow();//新行
tc=new TableCell();//空白列
tr.Cells.Add(tc);
//为每一个关联字段设置单选框,并将字段名作为它的ID.
CheckBox chk=null;
Label lb=null;
for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{
//一行9列,两边空白列,中间包括7个字段选择控件
if((i% 7) == 0 & i>0)
{
//一行尾部加一列
tc=new TableCell();
tc.Text=" ";
tr.Cells.Add(tc);
//另起一行并加一列空白列
Tbl.Rows.Add(tr);
tr=new TableRow();
tc=new TableCell();
tr.Cells.Add(tc);
}
tc=new TableCell();
tc.HorizontalAlign=HorizontalAlign.Right;
lb=new Label();
lb.Text=ds.Tables[0].Rows[i]["FieldAlias"].ToString();
tc.Controls.Add(lb);
chk=new CheckBox();
chk.ID=ds.Tables[0].Rows[i]["FieldName"].ToString();//为避免出现ID重复错误
//如果是标识字段则默认不钩选并不可编辑.
if(ds.Tables[0].Rows[i]["IsIdentity"].ToString() =="Y")
{
chk.Checked=false;
chk.Enabled=false;
}
tc.Controls.Add(chk);
tr.Cells.Add(tc);
}
//最后一行最后一个空白列的跨度设置为最大值.
tc=new TableCell();
tc.ColumnSpan=9;
tr.Cells.Add(tc);
Tbl.Rows.Add(tr);
//如果PrintedTable已有打印字段的内容(即编辑已有PrintedTable记录的情形),要分割以逗
//号隔开的字段集字符串,得到字段名并设置对应控件的钩选.
strSql="select RelatedFields from PrintedTable where
PrintedTableID="+printedtableid;
ds=basecode.SQLExeDataSet(strSql);
if(ds !=null & ds.Tables[0].Rows[0]["RelatedFields"] !=DBNull.Value)
{
string printedfieldsstr="";
printedfieldsstr=ds.Tables[0].Rows[0]["RelatedFields"].ToString().Trim();
if(printedfieldsstr != "")
{
string[] fieldsarray=new Tools().StringSplit(printedfieldsstr,",");
for(int j=0;j<fieldsarray.Length;j++)
{
//由于保存字段名字符串时最后还多一个",",使得字符串数组多一行空白字串,
//所以要判断.也可以将循环条件设置为j<fieldsarray.Length-1
if(fieldsarray[j] !="")
{
chk=(CheckBox)this.FindControl(fieldsarray[j]);
if(chk !=null)//避免找不到指定的控件
chk.Checked=true;
}
}
}
}
}//Page_Load()
//保存按钮
private void Button1_Click(object sender, System.EventArgs e)
{
SaveFields();
Response.Redirect("PrintedTable.aspx");
}
//放弃按钮
private void Button3_Click(object sender, System.EventArgs e)
{
Response.Redirect("PrintedTable.aspx");
}
//继续按钮(转到设置打印表格行页面,设计表格行)
private void Button2_Click(object sender, System.EventArgs e)
{
SaveFields();
Response.Redirect("PrintedRows.aspx?id="+ViewState["printedtableid"].ToString());
}
//保存打印字段
private void SaveFields()
{
//获取字段单选框列表的值
string printedtableid=ViewState["printedtableid"].ToString();
string chkedfields="";
//CheckBox chk=null;
DataSet ds=(DataSet)ViewState["relatedfields"];
for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{
CheckBox chk=(CheckBox)this.FindControl(ds.Tables[0]
.Rows[i]["FieldName"].ToString());
if(chk.Checked)
chkedfields=chkedfields+ds.Tables[0].Rows[i]["FieldName"].ToString()+",";
}
string strSql="update PrintedTable set RelatedFields='"+chkedfields+"' where
PrintedTableID="+printedtableid;
Base basecode=new Base();
if(! basecode.SQLExeNonQuery(strSql))
{
Label1.Text=basecode.BaseSqlErrDes;
return;
}
}
}
}
相关文章推荐
- 第七章 业务数据库的管理(七)-- 定义打印表格
- 第七章 业务数据库的管理(九)-- 打印表格行
- 第七章 业务数据库的管理(十一)-- 动态显示打印表格
- 第七章 业务数据库的管理(十)-- 打印表格行
- 第七章 电子政务系统对业务数据库的管理和使用(一)
- 第七章 业务数据库的管理(二)-- 数据库客户端工具
- 第七章 业务数据库的管理(四)-- 数据库客户端工具
- 第七章 业务数据库的管理(三)-- 数据库客户端工具
- 第七章 业务数据库的管理(五)-- C#动态创建控件
- 第七章 业务数据库的管理(六)
- 市内移出版本2.0(1、一页显示15条。2、增加控制标志。3、打印表格时绑定的list的优化。4、保存迁出登记信息时根据业务流水号判断增加还是修改。5、统一管理常量)
- 第七章 业务数据库的管理(十二)-- 设置业务数据共享
- 业务系统中用户权限数据库表格的设计2
- 源码-Oracle数据库管理-第七章-视图-Part 3(物化视图)
- 源码-Oracle数据库管理-第七章-视图-Part 2
- 使用Struts1从数据库下载,打印exsl表格
- 在多种数据库环境下管理业务需求
- 从数据库取出数据在jsp页面上以表格形式呈现,并对表格数据进行分页打印操作。
- 在业务逻辑中如何进行数据库的事务管理。
- 让mybatis支持管理和操作多个不同的业务数据库实例