首页 > Web开发 > 详细

.net软件开发脚本规范-代码标准(webform)

时间:2019-08-12 11:14:35      阅读:93      评论:0      收藏:0      [点我收藏+]

一、 代码标准

  1. 列表界面

1.1前台代码

1) 样式与js脚本,UI.css为界面样式,Font.css为字体样式,Common.js为通用基础js脚本,基本所有页面都需要,如果有需要新增的复制一行,修改href与src中的路径即可,保持统一格式,脚本的type在前src在后,样式的type与rel在前href在后。

2) 列表上方按钮:提交、新增、删除、查询、通过、不通过、导出Excel,根据需求减少按钮,顺序保持不变。

3) 底部的class为paging_table的表格为分页使用,如果不需要分页的列表,删除此表格,并删除后台对应的上一页btnPrePage_Click下一页btnNextpage_Click跳转到某一页drpGo_SelectedIndexChanged三个方法。

4) 注意列宽度分配美观性,宽度百分比加起来要为100%,第一列CHECKBOX固定为5%,操作列固定为10%,除非操作中包含多个按钮宽度不够时额外添加。

5) CHECKBOX后的第一列通常为标题,需要加上popWindow2弹出浏览页面,在此js方法中可以定义弹出页面的宽度与高度。

6) 创建步骤:

l 复制,完全复制替换新页面第一行以下的所有代码,并删除此页面中的第一行<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WorkPlanList.aspx.cs" Inherits="OfficeWork_WorkPlanList" %>。

修改文字,修改页面中的文字“工作计划”为新页面名称,包含头部“工作计划列表”与按钮的需要选择提醒“请先选择工作计划”,后台代码同样需要修改,使用替换功能替换前台与后台的“工作计划”为新页面名称。

l 修改按钮,根据需求减少列表上方的按钮,同时要删除相应的后台代码。

l 修改需要显示的列名。

修改与列对应的字段名,即视图中的字段名称,一般与列名相同,遇到日期转换的要注意加上“_显示”。

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WorkPlanList.aspx.cs" Inherits="OfficeWork_WorkPlanList" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head id="Head1" runat="server">

    <title>工作计划列表</title>

    <link type="text/css" rel="stylesheet" href="../STYLE/UI.css" />

    <link type="text/css" rel="stylesheet" href="../STYLE/Font.css" />

    <script type="text/javascript" src="../Script/Common.js"></script>

</head>

<body>

    <form id="form1" runat="server">

        <div>

            <table id="mainBox" cellspacing="0" cellpadding="0">

                <tr>

                    <td valign="top">

                        <table class="top">

                            <tr>

                                <td class="left_top"></td>

                                <td class="center_top">

                                    <p class="black_12_blod">工作计划列表</p>

                                </td>

                                <td class="right_top"></td>

                            </tr>

                        </table>

                    </td>

                </tr>

                <tr>

                    <td class="center content">

                        <center>

                            <table class="center_table">

                                <tr>

                                    <td>

                                        <table class="center_table_top">

                                            <tr>

                                                <td>

                                                    <asp:Image runat="server" ImageUrl="../IMG/ico/xs_xm.gif" /><asp:LinkButton ID="btnUp" runat="server" OnClick="btnUp_Click" OnClientClick="if (!sumCheck()){alert(‘请先选择工作计划‘);return false;}">提交</asp:LinkButton>

                                                    <asp:Image runat="server" ImageUrl="../IMG/ico/p_add.gif" /><asp:LinkButton ID="btnAdd" runat="server" OnClick="btnAdd_Click">新增</asp:LinkButton>

                                                    <asp:Image runat="server" ImageUrl="../IMG/ico/p_del.gif" /><asp:LinkButton ID="btnDel" runat="server" OnClick="btnDel_Click" OnClientClick="if (!sumCheck()){alert(‘请先选择工作计划‘);return false;}">删除</asp:LinkButton>

                                                    <asp:Image runat="server" ImageUrl="../IMG/ico/p_look.gif" /><asp:LinkButton ID="btnSearch" runat="server" OnClick="btnSearch_Click">查询</asp:LinkButton>

                                                    <asp:Image runat="server" ImageUrl="../IMG/ico/p_ok.gif" ID="imgPass" /><asp:LinkButton ID="btnPass" runat="server" OnClick="btnPass_Click" OnClientClick="if (!sumCheck()){alert(‘请先选择工作计划‘);return false;}">通过</asp:LinkButton>

                                                    <asp:Image runat="server" ImageUrl="../IMG/ico/p_err.gif" ID="imgNotpass" /><asp:LinkButton ID="btnNotPass" runat="server" OnClick="btnNotPass_Click" OnClientClick="if (!sumCheck()){alert(‘请先选择工作计划‘);return false;}">不通过</asp:LinkButton>

                                                    <asp:Image runat="server" ImageUrl="../IMG/ico/p_exc.gif" /><asp:LinkButton ID="btnExcel" runat="server" OnClick="btnExcel_Click">导出Excel</asp:LinkButton>

                                                </td>

                                            </tr>

                                        </table>

                                    </td>

                                </tr>

                                <tr>

                                    <td>

                                        <asp:DataList ID="list" runat="server" OnItemDataBound="list_ItemDataBound">

                                            <HeaderTemplate>

                                                <table class="list_head">

                                                    <tr class="black_12_blod">

                                                        <td width="5%" class="center_td">

                                                            <input type="checkbox" id="chkAll" onclick="checkAll()" /></td>

                                                        <td width="30%">学年学期</td>

                                                        <td width="15%">组名</td>

                                                        <td width="15%">申报人</td>

                                                        <td width="15%">附件</td>

                                                        <td width="10%">审核状态</td>

                                                        <td width="10%">操作</td>

                                                    </tr>

                                                </table>

                                            </HeaderTemplate>

                                            <ItemTemplate>

                                                <table class="list_item">

                                                    <tr>

                                                        <td width="5%" class="center_td">

                                                            <div class="inner_Style">

                                                                <asp:CheckBox ID="chkbox" runat="server" /><asp:HiddenField ID="hfId" runat="server" Value=‘<%#DataBinder.Eval(Container.DataItem, "编号")+","+DataBinder.Eval(Container.DataItem, "工作计划编号")%>‘ />

                                                            </div>

                                                        </td>

                                                        <td width="30%"><a href="javascript:void(0);" onclick=‘<%#"popWindow2(\"WorkPlanView.aspx?id="+DataBinder.Eval(Container.DataItem, "编号")+"&t_code="+DataBinder.Eval(Container.DataItem, "工作计划编号")+"\",700,500)"%>‘><%# DataBinder.Eval(Container.DataItem, "开始学年")%>~<%# DataBinder.Eval(Container.DataItem, "结束学年")%><%# DataBinder.Eval(Container.DataItem, "学期")%></a></td>

                                                        <td width="15%"><%# DataBinder.Eval(Container.DataItem, "组名")%></td>

                                                        <td width="15%"><%# DataBinder.Eval(Container.DataItem, "申报人员")%></td>

                                                        <td width="15%"><asp:LinkButton ID="btnUpfile" runat="server"></asp:LinkButton></td>

                                                        <td width="10%"><%# DataBinder.Eval(Container.DataItem, "审核状态")%></td>

                                                        <td width="10%" class="center_td">

                                                            <asp:LinkButton ID="btnEdit" CommandName=‘<%# DataBinder.Eval(Container.DataItem, "编号") %>‘ OnClick="btnEdit_Click" runat="server">[编辑]</asp:LinkButton>

                                                        </td>

                                                    </tr>

                                                </table>

                                            </ItemTemplate>

                                            <AlternatingItemTemplate>

                                                <table class="list_item_Alter">

                                                    <tr>

                                                        <td width="5%" class="center_td">

                                                            <div class="inner_Style">

                                                                <asp:CheckBox ID="chkbox" runat="server" /><asp:HiddenField ID="hfid" runat="server" Value=‘<%#DataBinder.Eval(Container.DataItem, "编号")+","+DataBinder.Eval(Container.DataItem, "工作计划编号")%>‘ />

                                                            </div>

                                                        </td>

                                                        <td width="30%"><a href="javascript:void(0);" onclick=‘<%#"popWindow2(\"WorkPlanView.aspx?id="+DataBinder.Eval(Container.DataItem, "编号")+"&t_code="+DataBinder.Eval(Container.DataItem, "工作计划编号")+"\",700,500)"%>‘><%# DataBinder.Eval(Container.DataItem, "开始学年")%>~<%# DataBinder.Eval(Container.DataItem, "结束学年")%><%# DataBinder.Eval(Container.DataItem, "学期")%></a></td>

                                                        <td width="15%"><%# DataBinder.Eval(Container.DataItem, "组名")%></td>

                                                        <td width="15%"><%# DataBinder.Eval(Container.DataItem, "申报人员")%></td>

                                                        <td width="15%"><asp:LinkButton ID="btnUpfile" runat="server"></asp:LinkButton></td>

                                                        <td width="10%"><%# DataBinder.Eval(Container.DataItem, "审核状态")%></td>

                                                        <td width="10%" class="center_td">

                                                            <asp:LinkButton ID="btnEdit" CommandName=‘<%# DataBinder.Eval(Container.DataItem, "编号") %>‘ OnClick="btnEdit_Click" runat="server">[编辑]</asp:LinkButton>

                                                        </td>

                                                    </tr>

                                                </table>

                                            </AlternatingItemTemplate>

                                        </asp:DataList>

                                        <asp:Label ID="lblReturnMsg" runat="server" class="msg"></asp:Label>

                                        <table class="paging_table">

                                            <tr>

                                                <td class="paging_table_left">【当前页:<asp:Label ID="lblCurPage" runat="server" Font-Bold="True" Font-Size="12px" ForeColor="#C00000">  </asp:Label>】    【共 <asp:Label ID="lblAllpage" runat="server" Font-Bold="True" Font-Size="12px" ForeColor="#C00000"></asp:Label> 页】    【共 <asp:Label ID="lblAlldata" runat="server" Font-Bold="True" Font-Size="12px" ForeColor="#C00000"></asp:Label> 条信息】</td>

                                                <td class="paging_table_right">   【<asp:LinkButton ID="btnPrePage" runat="server" OnClick="btnPrePage_Click">上一页</asp:LinkButton>】

                                                   【<asp:LinkButton ID="btnNextpage" runat="server" OnClick="btnNextpage_Click">下一页</asp:LinkButton>】

                                                <asp:DropDownList runat="server" ID="drpGo" Width="70" AutoPostBack="True" OnSelectedIndexChanged="drpGo_SelectedIndexChanged"></asp:DropDownList></td>

                                            </tr>

                                        </table>

                                    </td>

                                </tr>

                            </table>

                        </center>

                    </td>

                </tr>

                <tr>

                    <td>

                        <table class="foot">

                            <tr>

                                <td class="left_foot"></td>

                                <td class="center_foot"> </td>

                                <td class="right_foot"></td>

                            </tr>

                        </table>

                    </td>

                </tr>

            </table>

        </div>

    </form>

</body>

</html>

1.2后台代码

1) Page_Load方法,基本不需要修改,dlbind为数据绑定方法调用,RankHander为权限控制调用,如果不需要分页,删除页数定义;如果没有权限控制删除RankHander调用。

2) RankHander方法,权限控制,个人级的时候不显示通过与不通过按钮。

3) btnAdd_Click方法,对应【新增】按钮,跳转到新增页面,修改链接即可,一般情况下直接使用替换功能,比如新列表为工作总结命名为WorkSummary,将“WorkPlan”全部替换为“WorkSummary”即可。此示例中有type参数用于多菜单对应同页面不同类别功能,其他情况下不需要参数。

4) btnEdit_Click方法,对应列表中的【编辑】按钮,使用Session保存查询条件,修改链接即可(批量替换)。

5) btnDel_Click方法,对应【删除】按钮,修改参数@表名的参数值,修改提示文字(批量替换),如果是特殊情况不使用通用删除存储过程则需要修改存储过程名称以及参数,第一个@ReturnValue参数保持不变,根据返回值判断统计没有被删除的个数,如果大于0则弹出提醒。成功删除的需要记录操作日志,日志需要流水号,所以在前台的HiddenField中使用逗号拼接编号与流水号两个字符串,编号用于删除传参数,流水号用于记录日志。

6) btnPass_Click方法,对应【通过】按钮,修改参数@表名的参数值,修改提示文字(批量替换),成功审核的需要记录操作日志。

7) btnNotPass_Click方法,对应【不通过】按钮,修改参数@表名的参数值,修改提示文字(批量替换),成功审核的需要记录操作日志。

8) btnUp_Click方法,对应【提交】按钮,修改参数@表名的参数值,修改提示文字(批量替换),成功提交的需要记录操作日志。

9) btnSearch_Click方法,对应【查询】按钮,修改链接(批量替换),注意同新增大部分情况下不需要参数。

10) btnExcel_Click方法,对应【Excel导出】按钮,修改存储过程名称,修改表格名称(批量替换),注意如果存储过程中没有row_num列需要删除ds.Tables[0].Columns.Remove("row_num")。

11) dlbind方法,列表绑定方法,修改存储过程名称(批量替换),如果不需要分页,删除以下分页段代码。

Paging p = new Paging();

            p.RecordCount = Convert.ToInt32(sqlparam[0].Value);

            p.PageSize = 10;

            p.DoPaging(curpage, this.lblReturnMsg, this.lblCurPage, this.lblAllpage, this.lblAlldata, this.btnPrePage, this.btnNextpage, this.drpGo);

12) btnPrePage_Click方法,对应分页中的【上一页】按钮,固定方法不需要修改。

13) btnNextpage_Click方法,对应分页中的【下一页】按钮,固定方法不需要修改。

14) drpGo_SelectedIndexChanged方法,对应分页中的页数下拉列表,切换后跳转到选定页,固定方法不需要修改。

15) list_ItemDataBound方法,对应前台代码中的列表绑定事件,一般用于【编辑】按钮的颜色控制点击控制,此示例中还包含附件判断,如果附件不为空显示附件名称并点击后打开附件浏览页面。如果列表绑定时不需要特殊操作则删除此方法,并删除前台列表绑定事件中的OnItemDataBound事件<asp:DataList ID="list" runat="server" OnItemDataBound="list_ItemDataBound">

16) getParam方法,返回存储过程的参数组织,根据存储过程来设定参数,顺序需要与存储过程中相同,如果存储过程中是INT或DATETIME类型的需要使用IsNullToDBNull转换为DBNull.Value。

17) 创建步骤:

l 复制命名空间引用完全替换原命名空间。

l 复制所有方法完全替换原空文件中的方法。

l 批量替换 “工作计划”为新页面名称,批量替换前缀“GZJH_”。

l 对应前台按钮,如果需要减少方法删除相应的按钮和方法即可,注意所有方法顺序保持不变。

l 修改存储过程参数。

using System;

using System.Collections.Generic;

using System.Data;

using System.Data.SqlClient;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

 

public partial class OfficeWork_WorkPlanList : System.Web.UI.Page

{

    DataBase db = new DataBase();

    protected void Page_Load(object sender, EventArgs e)

    {

        if (Session["uid"] == null)

        {

            Response.Write("<script>parent.location=‘../index.html‘;</script>");

        }

        else

        {

            if (!IsPostBack)

            {

                this.lblCurPage.Text = "1";

                if (Request["curPage"] != null && Request["curPage"] != "")

                {

                    this.lblCurPage.Text = Request["curPage"].ToString();

                }

                dlbind();

                RankHander();

            }

        }

    }

 

    private void RankHander()

    {

        Cookie ck = new Cookie();

        if (ck.GetCookie("u_level") == "个人级")

        {

            imgPass.Visible = false;

            btnPass.Visible = false;

            imgNotpass.Visible = false;

            btnNotPass.Visible = false;

        }

        ck = null;

    }

 

    protected void btnAdd_Click(object sender, EventArgs e)

    {

        Response.Redirect("WorkPlanAdd.aspx?type=" + Request["type"], true);

    }

 

    protected void btnEdit_Click(object sender, EventArgs e)

    {

        BLL.setSearchSession(Request.QueryString.ToString());

 

        LinkButton lbn = (LinkButton)sender;

        string id = lbn.CommandName.ToString();

        Response.Redirect("WorkPlanAdd.aspx?act=edit&id=" + id + "&type=" + Request["type"] + "&curPage=" + this.lblCurPage.Text.ToString());

    }

 

    protected void btnDel_Click(object sender, EventArgs e)

    {

        try

        {

            int n = 0;

            Cookie ck = new Cookie();

            for (int i = 0; i < this.list.Items.Count; i++)

            {

                CheckBox chk = (CheckBox)this.list.Items[i].FindControl("chkbox");

                if (chk.Checked == true)

                {

                    HiddenField hfId = (HiddenField)this.list.Items[i].FindControl("hfId");

                    string[] str = hfId.Value.Split(‘,‘);

                    string id = str[0];

                    string code = str[1];

 

                    List<SqlParameter> sqlparam = new List<SqlParameter>();

                    SqlParameter param = new SqlParameter("@ReturnValue", SqlDbType.Int);

                    param.Direction = ParameterDirection.ReturnValue;

                    sqlparam.Add(param);

                    sqlparam.Add(new SqlParameter("@表名", "GZJH_工作计划"));

                    sqlparam.Add(new SqlParameter("@角色级别", ck.GetCookie("u_level")));

                    sqlparam.Add(new SqlParameter("@编号", id));

 

                    string rValue = db.ReturnValue("XT_通用删除", sqlparam.ToArray());

                    

                    if (rValue == "1")

                    {

                        BLL.WriteOperatLog("工作计划删除", code, "", "删除");

                    }

                    else

                    {

                        n++;

                    }

                }

            }

 

            if (n <= 0)

            {

                Response.Write("<script>alert(‘工作计划删除成功‘);</script>");

            }

            else

            {

                Response.Write("<script>alert(‘操作成功!其中有" + n + "个工作计划没有权限删除‘);</script>");

            }

            dlbind();

        }

        catch (Exception ex)

        {

            BLL.WriteErrorLog("工作计划删除", ex);

            Response.Write("<script>alert(‘操作发生错误‘);</script>");

        }

    }

 

    protected void btnPass_Click(object sender, EventArgs e)

    {

        try

        {

            int n = 0;

            Cookie ck = new Cookie();

            for (int i = 0; i < this.list.Items.Count; i++)

            {

                CheckBox chk = (CheckBox)this.list.Items[i].FindControl("chkbox");

                if (chk.Checked == true)

                {

                    HiddenField hfId = (HiddenField)this.list.Items[i].FindControl("hfId");

                    string[] str = hfId.Value.Split(‘,‘);

                    string id = str[0];

                    string code = str[1];

 

                    List<SqlParameter> sqlparam = new List<SqlParameter>();

                    SqlParameter param = new SqlParameter("@ReturnValue", SqlDbType.Int);

                    param.Direction = ParameterDirection.ReturnValue;

                    sqlparam.Add(param);

                    sqlparam.Add(new SqlParameter("@表名", "GZJH_工作计划"));

                    sqlparam.Add(new SqlParameter("@角色级别", ck.GetCookie("u_level")));

                    sqlparam.Add(new SqlParameter("@编号", id));

                    sqlparam.Add(new SqlParameter("@是否通过", 1));

 

                    string rValue = db.ReturnValue("XT_通用审核", sqlparam.ToArray());

 

                    if (rValue == "1")

                    {

                        BLL.WriteOperatLog("工作计划审核通过", code, "", "审核");

                    }

                    else

                    {

                        n++;

                    }

                }

            }

            if (n <= 0)

            {

                Response.Write("<script>alert(‘操作成功‘);</script>");

            }

            else

            {

                Response.Write("<script>alert(‘操作成功!其中有" + n + "个工作计划没有权限审核或是待完善状态‘);</script>");

            }

            dlbind();

        }

        catch (Exception em)

        {

            BLL.WriteErrorLog("工作计划审核通过", em);

            Response.Write("<script>alert(‘操作发生错误‘);window.location.href=‘WorkPlanList.aspx?type=" + Request["type"] + "‘;</script>");

        }

        finally

        {

            db = null;

            GC.Collect();

        }

    }

 

    protected void btnNotPass_Click(object sender, EventArgs e)

    {

        try

        {

            int n = 0;

            Cookie ck = new Cookie();

            for (int i = 0; i < this.list.Items.Count; i++)

            {

                CheckBox chk = (CheckBox)this.list.Items[i].FindControl("chkbox");

                if (chk.Checked == true)

                {

                    HiddenField hfId = (HiddenField)this.list.Items[i].FindControl("hfId");

                    string[] str = hfId.Value.Split(‘,‘);

                    string id = str[0];

                    string code = str[1];

 

                    List<SqlParameter> sqlparam = new List<SqlParameter>();

                    SqlParameter param = new SqlParameter("@ReturnValue", SqlDbType.Int);

                    param.Direction = ParameterDirection.ReturnValue;

                    sqlparam.Add(param);

                    sqlparam.Add(new SqlParameter("@表名", "GZJH_工作计划"));

                    sqlparam.Add(new SqlParameter("@角色级别", ck.GetCookie("u_level")));

                    sqlparam.Add(new SqlParameter("@编号", id));

                    sqlparam.Add(new SqlParameter("@是否通过", "0"));

 

                    string rValue = db.ReturnValue("XT_通用审核", sqlparam.ToArray());

 

                    if (rValue == "1")

                    {

                        BLL.WriteOperatLog("工作计划审核不通过", code, "", "审核");

                    }

                    else

                    {

                        n++;

                    }

                }

            }

            if (n <= 0)

            {

                Response.Write("<script>alert(‘操作成功‘);</script>");

            }

            else

            {

                Response.Write("<script>alert(‘操作成功!其中有" + n + "个工作计划没有权限审核或是待完善状态‘);</script>");

            }

            dlbind();

        }

        catch (Exception em)

        {

            BLL.WriteErrorLog("工作计划审核不通过", em);

            Response.Write("<script>alert(‘操作发生错误‘);window.location.href=‘WorkPlanList.aspx?type=" + Request["type"] + "‘;</script>");

        }

        finally

        {

            db = null;

            GC.Collect();

        }

    }

 

    protected void btnUp_Click(object sender, EventArgs e)

    {

        DataBase db = new DataBase();

        Cookie ck = new Cookie();

 

        try

        {

            int n = 0;

            for (int i = 0; i < this.list.Items.Count; i++)

            {

                CheckBox chk = (CheckBox)this.list.Items[i].FindControl("chkbox");

                if (chk.Checked == true)

                {

                    HiddenField hfId = (HiddenField)this.list.Items[i].FindControl("hfId");

                    string[] str = hfId.Value.Split(‘,‘);

                    string id = str[0];

                    string code = str[1];

 

                    List<SqlParameter> sqlparam = new List<SqlParameter>();

                    SqlParameter param = new SqlParameter("@ReturnValue", SqlDbType.Int);

                    param.Direction = ParameterDirection.ReturnValue;

                    sqlparam.Add(param);

                    sqlparam.Add(new SqlParameter("@表名", "GZJH_工作计划"));

                    sqlparam.Add(new SqlParameter("@角色级别", ck.GetCookie("u_level")));

                    sqlparam.Add(new SqlParameter("@编号", id));

                    sqlparam.Add(new SqlParameter("@是否通过", 2));

 

                    string rValue = db.ReturnValue("XT_通用审核", sqlparam.ToArray());

 

                    if (rValue == "1")

                    {

                        BLL.WriteOperatLog("工作计划提交", code, "", "提交");

                    }

                    else

                    {

                        n++;

                    }

                }

            }

            if (n <= 0)

            {

                Response.Write("<script>alert(‘操作成功‘);</script>");

            }

            else

            {

                Response.Write("<script>alert(‘操作成功!其中有" + n + "个工作计划不是待完善状态‘);</script>");

            }

            dlbind();

        }

        catch (Exception em)

        {

            BLL.WriteErrorLog("工作计划提交", em);

            Response.Write("<script>alert(‘操作发生错误‘);window.location.href=‘WorkPlanList.aspx?type=" + Request["type"] + "‘;</script>");

        }

        finally

        {

            db = null;

            GC.Collect();

        }

    }

 

    protected void btnSearch_Click(object sender, EventArgs e)

    {

        Response.Redirect("WorkPlanSearch.aspx?type=" + Request["type"]);

    }

 

    protected void btnExcel_Click(object sender, EventArgs e)

    {

        List<SqlParameter> sqlparam = getParam(-1, -1);

        DataSet ds = new DataSet();

        DataBase db = new DataBase();

        db.RunProc("GZJH_工作计划列表", sqlparam.ToArray(), ds);

        ds.Tables[0].Columns.Remove("row_num");

        ExportExcel.Export("工作计划", ds);

    }

 

    private void dlbind()

    {

        DataBase db = new DataBase();

        try

        {

            int curpage = int.Parse(this.lblCurPage.Text);

            List<SqlParameter> sqlparam = getParam(10, curpage);

            DataSet ds = new DataSet();

            db.RunProc("GZJH_工作计划列表", sqlparam.ToArray(), ds);

 

            Paging p = new Paging();

            p.RecordCount = Convert.ToInt32(sqlparam[0].Value);

            p.PageSize = 10;

            p.DoPaging(curpage, this.lblReturnMsg, this.lblCurPage, this.lblAllpage, this.lblAlldata, this.btnPrePage, this.btnNextpage, this.drpGo);

 

            this.list.DataSource = ds;

            this.list.DataBind();

        }

        catch (Exception ex)

        {

            BLL.WriteErrorLog("工作计划列表数据绑定", ex);

        }

        finally

        {

            db = null;

            GC.Collect();

        }

    }

 

    protected void btnPrePage_Click(object sender, EventArgs e)

    {

        this.lblCurPage.Text = Convert.ToString(Convert.ToInt32(this.lblCurPage.Text) - 1);

        drpGo.SelectedValue = this.lblCurPage.Text;

        dlbind();

    }

 

    protected void btnNextpage_Click(object sender, EventArgs e)

    {

        this.lblCurPage.Text = Convert.ToString(Convert.ToInt32(this.lblCurPage.Text) + 1);

        drpGo.SelectedValue = this.lblCurPage.Text;

        dlbind();

    }

 

    protected void drpGo_SelectedIndexChanged(object sender, EventArgs e)

    {

        this.lblCurPage.Text = drpGo.SelectedValue.ToString();

        dlbind();

        drpGo.SelectedValue = this.lblCurPage.Text;

    }

 

    protected void list_ItemDataBound(object sender, DataListItemEventArgs e)

    {

        try

        {

            if (e.Item.DataItem != null)

            {

                if (e.Item.FindControl("btnUpfile") != null)

                {

                    if (DataBinder.Eval(e.Item.DataItem, "附件路径").ToString() != "")

                    {

                        string fileUrl = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "附件路径"));

                        string fileName = fileUrl.Substring(fileUrl.LastIndexOf("/") + 1).Replace("pdf", "swf");

                        fileUrl = fileUrl.Substring(0, fileUrl.LastIndexOf("/") + 1).Replace("Pdf", "Swf");

                        ((LinkButton)e.Item.FindControl("btnUpfile")).OnClientClick = "popWindow2(‘../../PDFView/ShowAttachment.aspx?title=工作计划&path=" + fileUrl + "&fileName=" + fileName + "‘,800,700);return false;";

                        ((LinkButton)e.Item.FindControl("btnUpfile")).Text = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "附件名称"));

                    }

                }

 

                

                if (e.Item.FindControl("btnEdit") != null)

                {

                    string rstate = DataBinder.Eval(e.Item.DataItem, "审核状态编号").ToString();

                    Cookie ck = new Cookie();

                    if (ck.GetCookie("u_level") == "个人级" || ck.GetCookie("u_level") == "院系级")

                    {

                        if (rstate == "1" || rstate == "2")

                        {

                            ((LinkButton)e.Item.FindControl("btnEdit")).Enabled = false;

                            ((LinkButton)e.Item.FindControl("btnEdit")).Style.Add("color", "#9c9c9c");

                        }

                    }

                    else if (ck.GetCookie("u_level") == "校级")

                    {

                        if (rstate == "2")

                        {

                            ((LinkButton)e.Item.FindControl("btnEdit")).Enabled = false;

                            ((LinkButton)e.Item.FindControl("btnEdit")).Style.Add("color", "#9c9c9c");

                        }

                    }

                }

            }

        }

        catch (Exception ex)

        {

            BLL.WriteErrorLog("工作计划列表绑定", ex);

        }

    }   

 

    protected List<SqlParameter> getParam(int pageSize, int curPage)

    {

        Cookie ck = new Cookie();

 

        string depart = "";

        if (ck.GetCookie("u_level") == "院系级")

        {

            depart = ck.GetCookie("u_department");

        }

        else if (ck.GetCookie("u_level") == "校级")

        {

            depart = string.IsNullOrEmpty(Request["department"]) ? "" : Request["department"];

        }

        List<SqlParameter> sqlparam = new List<SqlParameter>();

        SqlParameter param = new SqlParameter("@RecordCount", SqlDbType.Int);

        param.Direction = ParameterDirection.Output;

        sqlparam.Add(param);

        sqlparam.Add(new SqlParameter("@角色级别", ck.GetCookie("u_level")));

        sqlparam.Add(new SqlParameter("@人员编号", Session["uid"].ToString()));

        sqlparam.Add(new SqlParameter("@所属单位", depart));

        sqlparam.Add(new SqlParameter("@工作计划分类", string.IsNullOrEmpty(Request["type"]) ? "" : Request["type"]));

        sqlparam.Add(new SqlParameter("@开始学年", string.IsNullOrEmpty(Request["drpStartYear"]) ? "" : Request["drpStartYear"]));

        sqlparam.Add(new SqlParameter("@结束学年", string.IsNullOrEmpty(Request["drpEndYear"]) ? "" : Request["drpEndYear"]));

        sqlparam.Add(new SqlParameter("@学期", string.IsNullOrEmpty(Request["drpTerm"]) ? "" : Request["drpTerm"]));

        sqlparam.Add(new SqlParameter("@组名", string.IsNullOrEmpty(Request["zm"]) ? "" : Request["zm"]));

        sqlparam.Add(new SqlParameter("@申报人员", string.IsNullOrEmpty(Request["applicant"]) ? "" : Request["applicant"]));

        sqlparam.Add(new SqlParameter("@申报日期1", string.IsNullOrEmpty(Request["requestDate1"]) ? "" : Request["requestDate1"]));

        sqlparam.Add(new SqlParameter("@申报日期2", string.IsNullOrEmpty(Request["requestDate2"]) ? "" : Request["requestDate2"]));

        sqlparam.Add(new SqlParameter("@审核状态", string.IsNullOrEmpty(Request["checkState"]) ? "" : Request["checkState"]));

        sqlparam.Add(new SqlParameter("@排序字段", string.IsNullOrEmpty(Request["sortfield"]) ? "" : Request["sortfield"]));

        sqlparam.Add(new SqlParameter("@排序模式", string.IsNullOrEmpty(Request["sortmode"]) ? "desc" : Request["sortmode"]));

        sqlparam.Add(new SqlParameter("@PageSize", pageSize));

        sqlparam.Add(new SqlParameter("@PageNum", curPage));

        return sqlparam;

    }

}

  1. 新增界面

2.1前台代码

1) 样式与js脚本,UI.css为界面样式,Font.css为字体样式,Common.js为通用基础js脚本,VerifyInput.js为控件验证通用脚本,包含是否为空、是否合格的数字类型日期类型等类型判断、是否正确的数值或日期范围判断,两个样式与两个js脚本基本所有页面都需要,Calender.js为日期插件,用于日期选择,如果界面上没有日期录入框则不需要,如果有自有js脚本如WorkPlan.js则放在最后一行。使用到jQuery脚本则放在倒数第二行。

2) 表单上方与上方均有三个按钮:保存、重置、返回,用于如果表单内容较多不需要再拉到最上方保存。

3) 如果是需要审核的表单,suggestPanel保持不变,要注意新表单如果是两列,要删审核意见的colspan属性。

4) 一般使用4列排版,如果内容较少使用两列排版。

5) 必填项在文字后面加红色*号。

6) 控件命名使用列名的英文简单翻译,尽量简短但能一看就明白。

7) 创建步骤:

l 复制,完全复制替换新页面第一行以下的所有代码,并删除此页面中的第一行<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WorkPlanAdd.aspx.cs" Inherits="OfficeWork_WorkPlanAdd" %>。

修改文字,使用替换功能替换“工作计划”为新页面名称。

l 修改表单内容,修改基本信息行以下的内容。

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WorkPlanAdd.aspx.cs" Inherits="OfficeWork_WorkPlanAdd" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>工作计划</title>

    <link type="text/css" rel="stylesheet" href="../style/UI.css" />

    <link type="text/css" rel="stylesheet" href="../style/Font.css" />

    <script type="text/javascript" src="../Script/Common.js"></script>

    <script type="text/javascript" src="../Script/VerifyInput.js"></script>

    <script type="text/javascript" src="../SCRIPT/Calender.js"></script>

    <script type="text/javascript" src="../Script/jquery-1.8.3.js"></script>

    <script type="text/javascript" src="Script/WorkPlan.js"></script>

</head>

<body>

    <form id="form1" runat="server">

        <div>

            <table id="mainBox" cellspacing="0" cellpadding="0">

                <tr>

                    <td>

                        <table class="top">

                            <tr>

                                <td class="left_top"></td>

                                <td class="center_top">

                                    <p class="black_12_blod">工作计划<asp:Label runat="server" ID="lblTitle" Text="" /></p>

                                </td>

                                <td class="right_top"></td>

                            </tr>

                        </table>

                    </td>

                </tr>

                <tr>

                    <td class="center content">

                        <center>

                            <table class="center_table">

                                <tr>

                                    <td>

                                        <table class="center_table_top">

                                            <tr>

                                                <td>

                                                    <asp:Image ID="imgSave" runat="server" ImageUrl="../IMG/ico/p_save.gif" /><asp:LinkButton ID="btnSave" runat="server" OnClientClick="return checkForm();" OnClick="btnSave_Click">保存</asp:LinkButton>

                                                    <asp:Image ID="imgReset" runat="server" ImageUrl="../IMG/ico/p_null.gif" /><asp:LinkButton ID="btnReset" runat="server" OnClientClick="javascript:form1.reset();return false;">重置</asp:LinkButton>

                                                    <asp:Image ID="imgBack" runat="server" ImageUrl="../IMG/ico/p_goback.gif" /><asp:LinkButton ID="btnBack" runat="server" OnClientClick="javascript:window.history.go(-1);return false;">返回</asp:LinkButton>

                                                </td>

                                            </tr>

                                        </table>

                                    </td>

                                </tr>

                                <tr>

                                    <td>

                                        <table class="content_table">

                                            <tr class="title">

                                                <td colspan="4">【基本信息】</td>

                                            </tr>

                                            <tr>

                                                <td>工作计划流水号</td>

                                                <td>

                                                    <asp:Label ID="lblCode" runat="server"></asp:Label>

                                                    <asp:HiddenField ID="hfId" runat="server" />

                                                </td>

                                                <td>申报日期<span class="red_12_normal"> *</span></td>

                                                <td>

                                                    <asp:TextBox ID="txtRequestDate" runat="server" onclick="if(!document.getElementById(‘calenderbox‘)){HS_setDate(this)}" onkeydown="if (event.keyCode!=8){return false;}" oncontextmenu="return false;"></asp:TextBox>

                                                </td>

                                            </tr>

                                            <tr>

                                                <td width="20%">学年度<span class="red_12_normal"> *</span></td>

                                                <td width="30%">

                                                    <asp:DropDownList ID="drpStartYear" runat="server"></asp:DropDownList>

                                                    ~

                                                    <asp:DropDownList ID="drpEndYear" runat="server"></asp:DropDownList>

                                                </td>

                                                <td width="20%">学期<span class="red_12_normal"> *</span></td>

                                                <td width="30%">

                                                    <asp:DropDownList ID="drpTerm" runat="server"></asp:DropDownList>

                                                </td>

                                            </tr>

                                            <tr>

                                                <td>申报人员</td>

                                                <td>

                                                    <asp:TextBox ID="txtApplicant" runat="server" Enabled="false"></asp:TextBox>

                                                    <asp:HiddenField ID="hfApplicant" runat="server"></asp:HiddenField>

                                                </td>

                                                <td>

                                                    <asp:Label ID="lblColName" runat="server"></asp:Label></td>

                                                <td>

                                                    <asp:TextBox ID="txtZm" runat="server" Visible="false"></asp:TextBox>

                                                </td>

                                            </tr>

                                            <tr>

                                                <td>附件</td>

                                                <td colspan="3">文件描述:<asp:TextBox ID="txtFileName" runat="server"></asp:TextBox><asp:HiddenField ID="hfFileUrl" runat="Server" />

                                                    <asp:FileUpload ID="fldFile" runat="server" Width="250px" /> <span class="deepgray_12_normal">格式:PDF;大小:20M</span>

                                                </td>

                                            </tr>

                                            <asp:Panel ID="suggestPanel" Visible="false" runat="server">

                                                <tr>

                                                    <td>审核意见:</td>

                                                    <td colspan="3">

                                                        <asp:TextBox ID="txtSuggest" runat="server" Width="400" MaxLength="250"></asp:TextBox>

                                                    </td>

                                                </tr>

                                            </asp:Panel>

                                        </table>

                                    </td>

                                </tr>

                                <tr>

                                    <td>

                                        <table class="center_table_top">

                                            <tr>

                                                <td>

                                                    <asp:Image ID="Image1" runat="server" ImageUrl="../IMG/ico/p_save.gif" /><asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="return checkForm();" OnClick="btnSave_Click">保存</asp:LinkButton>

                                                    <asp:Image ID="Image2" runat="server" ImageUrl="../IMG/ico/p_null.gif" /><asp:LinkButton ID="LinkButton2" runat="server" OnClientClick="javascript:form1.reset();return false;">重置</asp:LinkButton>

                                                    <asp:Image ID="Image3" runat="server" ImageUrl="../IMG/ico/p_goback.gif" /><asp:LinkButton ID="LinkButton3" runat="server" OnClientClick="javascript:window.history.go(-1);return false;">返回</asp:LinkButton>

                                                </td>

                                            </tr>

                                        </table>

                                    </td>

                                </tr>

                            </table>

                        </center>

                    </td>

                </tr>

                <tr>

                    <td>

                        <table class="foot">

                            <tr>

                                <td class="left_foot"></td>

                                <td class="center_foot"> </td>

                                <td class="right_foot"></td>

                            </tr>

                        </table>

                    </td>

                </tr>

            </table>

        </div>

    </form>

</body>

</html>

2.2后台代码

1) Page_Load方法,下拉列表数据均从BaseData类中调用,修改状态如果不是个人级则显示审核意见录入框,流水号统一使用Label控件,名称为lblCode,使用getCode方法赋值,修改简拼同数据库表简拼,BaseData.getCode("GZJH", lblCode)

2) BindData方法,用于修改时候加载原数据,修改浏览存储过程名称,再修改控件赋值段落。

3) btnSave_Click方法,对应【保存】按钮,少量新增修改有差异的参数赋值写在各自存储过程调用之前,如示例中的@附件路径参数,修改存储过程名称,修改提示信息即可。注意修改状态中的pagestr与search参数赋值段不可删除,用于编辑后依然保留在原页面。

4) getParam方法,返回存储过程的参数组织,根据存储过程来设定参数,顺序需要与存储过程中相同,如果存储过程中是INT或DATETIME类型的需要使用IsNullToDBNull转换为DBNull.Value。

5) 创建步骤:

l 复制命名空间引用完全替换原命名空间。

l 复制所有方法完全替换原空文件中的方法。

l 批量替换 “工作计划”为新页面名称,批量替换前缀“GZJH_”,再替换一遍“GZJH”。

l 修改基础数据加载段,即页面上的DropDownList,RadioButtonList等控件的数据加载功能。

l 修改BindData数据加载绑定方法中的控件名称及赋值。

l 修改存储过程参数。

using System;

using System.Collections.Generic;

using System.Data;

using System.Data.SqlClient;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

 

public partial class OfficeWork_WorkPlanAdd : System.Web.UI.Page

{

    DataBase db = new DataBase();

    protected void Page_Load(object sender, EventArgs e)

    {

 

        if (Session["uid"] == null)//判断用户是否超时

        {

            Response.Write("<script>parent.location=‘../index.html‘;</script>");

        }

        else

        {

            if (!IsPostBack)

            {

                BaseData.BindYear(drpStartYear, DateTime.Now);

                BaseData.BindYear(drpEndYear, DateTime.Now);

                BaseData.Term(drpTerm, true, true);

                switch (Request["type"])

                {

                    case "1":

                        txtZm.Visible = true;

                        lblColName.Text = "学科组";

                        break;

                    case "3":

                        txtZm.Visible = true;

                        lblColName.Text = "备课组";

                        break;

                    case "5":

                        txtZm.Visible = true;

                        lblColName.Text = "班务";

                        break;

                }

 

                Cookie ck = new Cookie();

 

                if (Request["act"] == "edit")

                {

                    if (ck.GetCookie("u_level") != "个人级")

                    {

                        suggestPanel.Visible = true;

                    }

                    lblTitle.Text = "修改";

                    BindData(Request["id"]);

                }

                else

                {

                    lblTitle.Text = "新增";

                    txtApplicant.Text = ck.GetCookie("u_showname");

                    hfApplicant.Value = Convert.ToString(Session["uid"]);

                    txtRequestDate.Text = DateTime.Now.ToString("yyyy-MM-dd");

                    BaseData.getCode("GZJH", lblCode);

                }

            }

        }

    }

 

    protected void BindData(string id)

    {

        DataBase db = new DataBase();

        try

        {

            if (Session["uid"] != null)

            {

                List<SqlParameter> sqlparam = new List<SqlParameter>();

                sqlparam.Add(new SqlParameter("@编号", id));

 

                DataSet ds = new DataSet();

                db.RunProc("GZJH_工作计划浏览", sqlparam.ToArray(), ds);

 

                if (ds != null)

                {

                    if (ds.Tables[0].Rows.Count > 0)

                    {

                        hfId.Value = id;

                        lblCode.Text = ds.Tables[0].Rows[0]["工作计划编号"].ToString();

                        drpStartYear.SelectedValue = ds.Tables[0].Rows[0]["开始学年"].ToString();

                        drpEndYear.SelectedValue = ds.Tables[0].Rows[0]["结束学年"].ToString();

                        drpTerm.SelectedValue = ds.Tables[0].Rows[0]["学期编号"].ToString();

                        txtApplicant.Text = ds.Tables[0].Rows[0]["申报人员"].ToString();

                        hfApplicant.Value = ds.Tables[0].Rows[0]["申报人员编号"].ToString();

                        txtZm.Text = ds.Tables[0].Rows[0]["组名"].ToString();

                        txtFileName.Text = Convert.ToString(ds.Tables[0].Rows[0]["附件名称"]);

                        hfFileUrl.Value = Convert.ToString(ds.Tables[0].Rows[0]["附件路径"]);

                        txtRequestDate.Text = Convert.ToString(ds.Tables[0].Rows[0]["申报日期"]);

                        txtSuggest.Text = ds.Tables[0].Rows[0]["审核意见"].ToString();

                        ds = null;

                    }

                    else

                    {

                        Response.Write("<script>alert(‘没有数据‘);window.location=‘WorkPlanList.aspx‘;</script>");

                    }

                }

            }

            else

            {

                Response.Write("<script>parent.location=‘../index.html‘;</script>");

            }

        }

        catch (Exception ex)

        {

            BLL.WriteErrorLog("获取工作计划浏览数据", ex);

        }

        finally

        {

            db = null;

            GC.Collect();

        }

    }

 

    protected void btnSave_Click(object sender, EventArgs e)

    {

        try

        {

            string fileUrl = UploadFile.UpFileToSwf(fldFile, UpFileType.OfficeWork);

            if (fileUrl == "1")

            {

                Response.Write("<script language=‘javascript‘>alert(‘支持格式:|pdf|‘);</script>");

            }

            else if (fileUrl == "2")

            {

                Response.Write("<script language=‘javascript‘>alert(‘你的文件已经超过20M的大小!‘);</script>");

            }

            else

            {

                List<SqlParameter> sqlparam = getParam();

                if (Request["act"] == "edit")

                {

                    sqlparam.Add(new SqlParameter("@附件路径", (fileUrl == "") ? hfFileUrl.Value : fileUrl));

                    db.RunProc("GZJH_工作计划修改", sqlparam.ToArray());

                    BLL.WriteOperatLog("工作计划修改", lblCode.Text.Trim(), txtApplicant.Text.Trim(), "修改");

                    

                    string pagestr = "", search = "";

                    if (Request["curPage"] != null && Request["curPage"] != "")

                    {

                        pagestr = "curPage=" + Request["curPage"].ToString();

                    }

                    if (Session["search"] != null && Session["search"].ToString() != "")

                    {

                        search = Session["search"].ToString();

                        Session.Remove("search");

                    }

                    Response.Write("<script>alert(‘工作计划修改成功‘);window.location=‘WorkPlanList.aspx?" + search + "&" + pagestr + "‘;</script>");

                }

                else

                {

                    sqlparam.Add(new SqlParameter("@附件路径", fileUrl));

                    db.RunProc("GZJH_工作计划新增", sqlparam.ToArray());

                    BLL.WriteOperatLog("工作计划新增", lblCode.Text.Trim(), txtApplicant.Text.Trim(), "新增");

                    Response.Write("<script>alert(‘工作计划新增成功‘);window.location=‘WorkPlanList.aspx?type=" + Request["type"] + "‘;</script>");

                }

            }

        }

        catch (Exception ex)

        {

            if (Request["act"] == "edit")

            {

                BLL.WriteErrorLog("工作计划修改", ex);

                Response.Write("<script>alert(‘修改工作计划失败‘);window.location=‘WorkPlanList.aspx?type=" + Request["type"] + "‘;</script>");

            }

            else

            {

                BLL.WriteErrorLog("工作计划新增", ex);

                Response.Write("<script>alert(‘新增工作计划失败‘);window.location=‘WorkPlanAdd.aspx?type=" + Request["type"] + "‘;</script>");

            }

        }

    }

 

    protected List<SqlParameter> getParam()

    {

        List<SqlParameter> sqlparam = new List<SqlParameter>();

        if (Request["act"] == "edit")

        {

            sqlparam.Add(new SqlParameter("@编号", hfId.Value));

        }

        sqlparam.Add(new SqlParameter("@工作计划编号", lblCode.Text));

        sqlparam.Add(new SqlParameter("@工作计划分类", Request["type"]));

        sqlparam.Add(new SqlParameter("@开始学年", drpStartYear.SelectedValue));

        sqlparam.Add(new SqlParameter("@结束学年", drpEndYear.SelectedValue));

        sqlparam.Add(new SqlParameter("@学期", drpTerm.SelectedValue));

        sqlparam.Add(new SqlParameter("@组名", txtZm.Text));

        sqlparam.Add(new SqlParameter("@申报人员", hfApplicant.Value));

        sqlparam.Add(new SqlParameter("@申报日期", txtRequestDate.Text));

        sqlparam.Add(new SqlParameter("@审核意见", txtSuggest.Text));

        sqlparam.Add(new SqlParameter("@附件名称", txtFileName.Text));

        return sqlparam;

    }

}

  1. 浏览界面

3.1前台代码

1) 样式与js脚本,UI.css为界面样式,Font.css为字体样式,Common.js为通用基础js脚本,OperationTrack.js为操作追踪通用脚本,操作追踪脚本使用到jQuery框架。

2) 表单排版需要与新增界面一摸一样,控件大部分为Label,命名与新增界面一致,前缀由txt、drp、rdo等改为lbl,如“txtName”改为“lblName”。

3) 如果是不需要审核的表单,删除意见信息模块。

4) 创建步骤:

l 复制,完全复制替换新页面第一行以下的所有代码,并删除此页面中的第一行。

修改文字,使用替换功能替换“工作计划”为新页面名称。

修改表单内容,可以从新增界面中复制,批量替换控件,“TextBox”、“DropdownList”等为“Label”,批量替换前缀“txt”、“drp”等为“lbl”,少量特殊控件另外修改。

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WorkPlanView.aspx.cs" Inherits="OfficeWork_WorkPlanView" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head id="Head1" runat="server">

    <title>工作计划浏览</title>

    <link type="text/css" rel="stylesheet" href="../STYLE/UI.css" />

    <link type="text/css" rel="stylesheet" href="../STYLE/Font.css" />

    <script type="text/javascript" src="../Script/Common.js"></script>

    <script type="text/javascript" src="../Script/jquery-1.8.3.js"></script>

    <script type="text/javascript" src="../Script/OperationTrack.js"></script>

</head>

<body>

    <form id="form1" runat="server">

        <div>

            <table id="mainBox" cellspacing="0" cellpadding="0">

                <tr>

                    <td>

                        <table class="top">

                            <tr>

                                <td class="left_top"></td>

                                <td class="center_top">

                                    <p class="black_12_blod">工作计划浏览</p>

                                </td>

                                <td class="right_top"></td>

                            </tr>

                        </table>

                    </td>

                </tr>

                <tr>

                    <td class="center content">

                        <center>

                            <table class="center_table">

                                <tr>

                                    <td>

                                        <table class="content_table">

                                            <tr class="title">

                                                <td colspan="4">【基本信息】</td>

                                            </tr>

                                            <tr>

                                                <td>工作计划流水号:<span class="red_12_normal"> *</span></td>

                                                <td colspan="3">

                                                    <asp:Label ID="lblCode" runat="server"></asp:Label>

                                                </td>

                                            </tr>

                                            <tr style="">

                                                <td width="20%">学年度</td>

                                                <td width="30%">

                                                    <asp:Label runat="server" ID="lblStartYear" />

                                                    ~

                                                    <asp:Label runat="server" ID="lblEndYear" />

                                                </td>

                                                <td width="20%">学期</td>

                                                <td width="30%">

                                                    <asp:Label runat="server" ID="lblTerm" />

                                                </td>

                                            </tr>

                                            <tr style="">

                                                <td>申报人</td>

                                                <td>

                                                    <asp:Label runat="server" ID="lblApplicant" />

                                                </td>

                                                <td>

                                                    <asp:Label ID="lblColName" runat="server"></asp:Label></td>

                                                <td>

                                                    <asp:Label runat="server" ID="lblzm" />

                                                </td>

                                            </tr>

                                            <tr style="">

                                                <td>附件</td>

                                                <td colspan="4">

                                                    <asp:HyperLink ID="hlFile" runat="server" Target="_blank"></asp:HyperLink>

                                                </td>

                                            </tr>

                                            <tr class="title">

                                                <td colspan="4">【意见信息】</td>

                                            </tr>

                                            <tr>

                                                <td>意见内容:</td>

                                                <td colspan="3">

                                                    <asp:Label ID="lblSuggest" runat="server" Visible="false"></asp:Label>

                                                    <asp:TextBox ID="txtSuggest" runat="server" TextMode="MultiLine" Width="350" Rows="3" Visible="false"></asp:TextBox>

                                                     <asp:Button ID="btnSaveSuggest" runat="server" Text="保存意见" OnClick="btnSaveSuggest_Click" Visible="false" />

                                                </td>

                                            </tr>

                                            <tr class="title">

                                                <td colspan="4">【操作跟踪】</td>

                                            </tr>

                                            <tr>

                                                <td colspan="4">

                                                    <div id="operateTrack"></div>

                                                    <div id="seemore">

                                                        <asp:Image ID="Image1" runat="server" ImageUrl="../IMG/arrow.png" /><a href="javascript:void(0);" id="btnSeeMore">展开查看更多...</a>

                                                    </div>

                                                </td>

                                            </tr>

                                        </table>

                                    </td>

                                </tr>

                            </table>

                        </center>

                    </td>

                </tr>

                <tr>

                    <td>

                        <table class="foot">

                            <tr>

                                <td class="left_foot"></td>

                                <td class="center_foot"> </td>

                                <td class="right_foot"></td>

                            </tr>

                        </table>

                    </td>

                </tr>

            </table>

        </div>

    </form>

</body>

</html>

3.2后台代码

1) Page_Load方法,基本完全一致,只有BindData方法调用

2) BindData方法,用于加载绑定数据,修改浏览存储过程名称,再修改控件赋值段落。

3) btnSaveSuggest_Click方法,对应【保存意见】按钮,此示例为保存在本表中,通用示例请参考论文中的写法。

protected void btnSaveSuggest_Click(object sender, EventArgs e)

    {

        if (txtsuggest.Text.Trim() != "")

        {

            OfficeHelper.SaveAuditSuggest(code.Text, txtsuggest.Text.Trim(), HttpContext.Current.Session["uid"].ToString());

            Response.Write("<script>alert(‘保存成功‘);</script>");

        }

        else

        {

            Response.Write("<script>alert(‘您没有填写意见‘);</script>");

        }

    }

4) 创建步骤:

l 复制命名空间引用完全替换原命名空间。

l 复制所有方法完全替换原空文件中的方法。

l 批量替换 “工作计划”为新页面名称,批量替换前缀“GZJH_”。

l 修改BindData方法中,从新增页面中赋值,替换控件前缀“txt”、“drp”等为“lbl”,原来读取编号的去掉“编号”两字,附件类似的赋值另外写。

using System;

using System.Collections.Generic;

using System.Data;

using System.Data.SqlClient;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

 

public partial class OfficeWork_WorkPlanView : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        if (Session["uid"] == null)

        {

            Response.Write("<script>parent.location=‘../index.html‘;</script>");

        }

        else

        {

            if (!IsPostBack)

            {

                switch (Request["type"])

                {

                    case "1":

                        lblzm.Visible = true;

                        lblColName.Text = "学科组";

                        break;

                    case "3":

                        lblzm.Visible = true;

                        lblColName.Text = "备课组";

                        break;

                    case "5":

                        lblzm.Visible = true;

                        lblColName.Text = "班务";

                        break;

                }

 

                BindData(Request["id"]);

            }

        }

    }

 

    private void BindData(string id)

    {

        DataBase db = new DataBase();

        try

        {

            if (Session["uid"] != null)

            {

                List<SqlParameter> sqlparam = new List<SqlParameter>();

                sqlparam.Add(new SqlParameter("@编号", id));

                DataSet ds = new DataSet();

                db.RunProc("GZJH_工作计划浏览", sqlparam.ToArray(), ds);

 

                if (ds != null)

                {

                    if (ds.Tables[0].Rows.Count > 0)

                    {                       

                        lblCode.Text = ds.Tables[0].Rows[0]["工作计划编号"].ToString();

                        lblStartYear.Text = ds.Tables[0].Rows[0]["开始学年"].ToString();

                        lblEndYear.Text = ds.Tables[0].Rows[0]["结束学年"].ToString();

                        lblTerm.Text = ds.Tables[0].Rows[0]["学期"].ToString();

                        lblApplicant.Text = ds.Tables[0].Rows[0]["申报人员"].ToString();

                        lblzm.Text = ds.Tables[0].Rows[0]["组名"].ToString();

                        if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["附件路径"].ToString()))

                        {

                            hlFile.Text = "<img src=‘../../IMG/ico/down.jpg‘ border=‘0‘ />" + ds.Tables[0].Rows[0]["附件名称"].ToString();

                            hlFile.NavigateUrl = "../" + ds.Tables[0].Rows[0]["附件路径"].ToString();

                        }

                        lblSuggest.Text = ds.Tables[0].Rows[0]["审核意见"].ToString();

                        txtSuggest.Text = ds.Tables[0].Rows[0]["审核意见"].ToString();

 

                        Cookie ck = new Cookie();

                        string state = ds.Tables[0].Rows[0]["审核状态编号"].ToString();

                        string ulevel = ck.GetCookie("u_level");

                        if (ulevel == "个人级" || (ulevel == "校级" && state == "2") || (ulevel == "院系级" && state == "1"))

                        {

                            lblSuggest.Visible = true;

                        }

                        else

                        {

                            txtSuggest.Visible = true;

                            btnSaveSuggest.Visible = true;

                        }

                        ck = null;

                        ds = null;

                    }

                    else

                    {

                        Response.Write("<script>alert(‘没有数据‘);window.location=‘WorkPlanList.aspx‘;</script>");

                    }

                }

            }

            else

            {

                Response.Write("<script>parent.location=‘../index.html‘;</script>");

            }

        }

        catch (Exception ex)

        {

            BLL.WriteErrorLog("工作计划浏览", ex);

        }

        finally

        {

            db = null;

            GC.Collect();

        }

    }

 

    protected void btnSaveSuggest_Click(object sender, EventArgs e)

    {

        if (txtSuggest.Text.Trim() != "")

        {

            string sql = "UPDATE GZJH_工作计划 SET 审核意见=‘" + txtSuggest.Text + "‘ WHERE 编号=" + Request["id"];

            DataBase db = new DataBase();

            db.RunProc(sql);

            Response.Write("<script>alert(‘保存成功‘);</script>");

        }

        else

        {

            Response.Write("<script>alert(‘您没有填写意见‘);</script>");

        }

    }

}

  1. 查询界面

4.1前台代码

1) 样式与js脚本同新增界面,新增界面检查表单填写调用checkForm方法,查询界面检查表单填写调用checkSearchForm方法。

2) 表单排版顺序需要与新增界面一摸一样,新增界面上除了描述之类的都要做为查询条件,另外加上条件所属单位,审核状态。

3) 数值与日期使用一个范围,一个填写则另一个必须填写。

4) 排序字段与列表中显示的列对应。

5) 创建步骤:

l 复制,完全复制替换新页面第一行以下的所有代码,并删除此页面中的第一行。

修改文字,使用替换功能替换“工作计划”为新页面名称。

l 修改表单内容,可以从新增界面中复制,再做修改。

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WorkPlanSearch.aspx.cs" Inherits="OfficeWork_WorkPlanSearch" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head id="Head1" runat="server">

    <title>工作计划查询</title>

    <link type="text/css" rel="stylesheet" href="../Style/UI.css" />

    <link type="text/css" rel="stylesheet" href="../Style/Font.css" />

    <script type="text/javascript" src="../Script/Common.js"></script>

    <script type="text/javascript" src="../Script/VerifyInput.js"></script>

    <script type="text/javascript" src="../SCRIPT/Calender.js"></script>

    <script type="text/javascript" src="../Script/jquery-1.8.3.js"></script>

    <script type="text/javascript" src="Script/WorkPlan.js"></script>

</head>

<body>

    <form id="form1" runat="server" method="post">

        <div>

            <table id="mainBox" cellspacing="0" cellpadding="0">

                <tr>

                    <td>

                        <table class="top">

                            <tr>

                                <td class="left_top"></td>

                                <td class="center_top">

                                    <p class="black_12_blod">工作计划查询</p>

                                </td>

                                <td class="right_top"></td>

                            </tr>

                        </table>

                    </td>

                </tr>

                <tr>

                    <td class="center content">

                        <center>

                            <table class="center_table">

                                <tr>

                                    <td>

                                        <table class="center_table_top">

                                            <tr>

                                                <td>

                                                    <asp:Image ID="imgLook" runat="server" ImageUrl="../IMG/ico/p_look.gif" /><asp:LinkButton ID="btnSearch" runat="server" OnClick="btnSearch_Click" OnClientClick="return checkSearchForm()">查找</asp:LinkButton>

                                                    <asp:Image ID="imgBack" runat="server" ImageUrl="../IMG/ico/p_goback.gif" /><asp:LinkButton ID="btnBack" runat="server" OnClientClick="javascript:window.history.go(-1);return false;">返回</asp:LinkButton>

                                                </td>

                                            </tr>

                                        </table>

                                    </td>

                                </tr>

                                <tr>

                                    <td>

                                        <table class="content_table">

                                            <tr class="title">

                                                <td height="25" style="text-align: left;" colspan="4">【查询条件】</td>

                                            </tr>

                                            <tr>

                                                <td>申报时间</td>

                                                <td colspan="3">

                                                    <asp:TextBox ID="txtRequestDate1" Style="width: 80px;" runat="server" onclick="if(!document.getElementById(‘calenderbox‘)){HS_setDate(this)}" onkeydown="if (event.keyCode!=8){return false;}" oncontextmenu="return false;"></asp:TextBox>到

                                                    <asp:TextBox ID="txtRequestDate2" Style="width: 80px;" runat="server" onclick="if(!document.getElementById(‘calenderbox‘)){HS_setDate(this)}" onkeydown="if (event.keyCode!=8){return false;}" oncontextmenu="return false;"></asp:TextBox>

                                                </td>

                                            </tr>

                                            <tr>

                                                <td width="20%">学年度</td>

                                                <td width="30%">

                                                    <asp:DropDownList ID="drpStartYear" runat="server"></asp:DropDownList>

                                                    ~

                                                    <asp:DropDownList ID="drpEndYear" runat="server"></asp:DropDownList>

                                                </td>

                                                <td width="20%">学期</td>

                                                <td width="30%">

                                                    <asp:DropDownList ID="drpTerm" runat="server"></asp:DropDownList>

                                                </td>

                                            </tr>

                                            <tr>

                                                <td>申报人</td>

                                                <td>

                                                    <asp:TextBox ID="txtApplicant" runat="server"></asp:TextBox>

                                                </td>

                                                <td>组名</td>

                                                <td>

                                                    <asp:TextBox ID="txtZm" runat="server"></asp:TextBox>

                                                </td>

                                            </tr>

                                            <tr>

                                                <td>所属单位</td>

                                                <td>

                                                    <asp:DropDownList ID="drpDepart" runat="server"></asp:DropDownList>

                                                </td>

                                                <td>审核状态</td>

                                                <td>

                                                    <asp:DropDownList ID="drpCheckState" runat="server"></asp:DropDownList>

                                                </td>

                                            </tr>

                                            <tr class="title">

                                                <td colspan="4">【排序条件】</td>

                                            </tr>

                                            <tr>

                                                <td>排序字段:</td>

                                                <td>

                                                    <asp:DropDownList runat="server" ID="drpOrderfiled">

                                                        <asp:ListItem Value="">请选择</asp:ListItem>

                                                        <asp:ListItem Value="工作计划编号">工作计划编号</asp:ListItem>

                                                        <asp:ListItem Value="开始学年">开始学年</asp:ListItem>

                                                        <asp:ListItem Value="结束学年">结束学年</asp:ListItem>

                                                        <asp:ListItem Value="学期">学期</asp:ListItem>

                                                        <asp:ListItem Value="申报人员">申报人员</asp:ListItem>

                                                        <asp:ListItem Value="所属单位">所属单位</asp:ListItem>

                                                        <asp:ListItem Value="审核状态">审核状态</asp:ListItem>

                                                    </asp:DropDownList>

                                                </td>

                                                <td>排序方式:</td>

                                                <td>

                                                    <asp:DropDownList runat="server" ID="drpOrdermodel">

                                                        <asp:ListItem Value="">请选择</asp:ListItem>

                                                        <asp:ListItem Value="ASC">升序</asp:ListItem>

                                                        <asp:ListItem Value="DESC">降序</asp:ListItem>

                                                    </asp:DropDownList>

                                                </td>

                                            </tr>

                                        </table>

                                    </td>

                                </tr>

                                <tr>

                                    <td>

                                        <table class="center_table_top">

                                            <tr>

                                                <td>

                                                    <asp:Image ID="Image1" runat="server" ImageUrl="../IMG/ico/p_look.gif" /><asp:LinkButton ID="LinkButton1" runat="server" OnClick="btnSearch_Click">查找</asp:LinkButton>

                                                    <asp:Image ID="Image2" runat="server" ImageUrl="../IMG/ico/p_goback.gif" /><asp:LinkButton ID="LinkButton2" runat="server" OnClientClick="javascript:window.history.go(-1);return false;">返回</asp:LinkButton>

                                                </td>

                                            </tr>

                                        </table>

                                    </td>

                                </tr>

                            </table>

                        </center>

                    </td>

                </tr>

                <tr>

                    <td>

                        <table class="foot">

                            <tr>

                                <td class="left_foot"></td>

                                <td class="center_foot"> </td>

                                <td class="right_foot"></td>

                            </tr>

                        </table>

                    </td>

                </tr>

            </table>

        </div>

    </form>

</body>

</html>

4.2后台代码

1) Page_Load方法,需要修改其中的下拉基础数据加载方法,同新增页面

2) btnSearch_Click方法,修改其中的链接页面与参数,参数名称与列表的getParam方法中完全一致。

3) 创建步骤:

l 复制命名空间引用完全替换原命名空间。

l 复制所有方法完全替换原空文件中的方法。

l 复制新增页面中的基础数据加载方法。

l 修改链接页面与参数。

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

 

public partial class OfficeWork_WorkPlanSearch : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        if (Session["uid"] == null)

        {

            Response.Write("<script>parent.location=‘../index.html‘;</script>");

        }

        else

        {

            if (!IsPostBack)

            {

                BaseData.BindYear(drpStartYear, DateTime.Now);

                BaseData.BindYear(drpEndYear, DateTime.Now);

                BaseData.Term(drpTerm, true, true);

                BaseData.CheckState(drpCheckState, 1);

                BaseData.Depart(drpDepart, false, true);

            }

        }

    }

 

    protected void btnSearch_Click(object sender, EventArgs e)

    {

        string urlstr = "WorkPlanList.aspx?type=" + Request["type"] + "&drpStartYear=" + drpStartYear.SelectedValue + "&drpEndYear=" + drpEndYear.SelectedValue

            + "&drpTerm=" + drpTerm.SelectedValue + "&applicant=" + txtApplicant.Text.Trim() + "&zm=" + txtZm.Text.Trim()

            + "&department=" + drpDepart.SelectedValue + "&checkState=" + drpCheckState.SelectedValue

            + "&requestDate1=" + txtRequestDate1.Text.Trim() + "&requestDate2=" + txtRequestDate2.Text

            + "&sortfield=" + drpOrderfiled.Text + "&sortmode=" + drpOrdermodel.Text;

        Response.Redirect(urlstr);

    }

}

.net软件开发脚本规范-代码标准(webform)

原文:https://www.cnblogs.com/wupeng6/p/11337836.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!