简单增删改模式

1)前台aspx页面

 

<%@ Page  Theme="gray" Language="C#" AutoEventWireup="true" CodeFile="iv_degree.aspx.cs" Inherits="HRM_config_iv_degree" %>

<!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 media="all" href="http://www.cnblogs.com/style/bar.css" type="text/css" rel="stylesheet"/>
 <link media="all" href="http://www.cnblogs.com/style/input.css" type="text/css" rel="stylesheet">
 <script type="text/javascript" src="http://www.cnblogs.com/js/dropdowntabs.js"></script>
    <script language="JavaScript" src="http://www.cnblogs.com/js/calendar_ajax.js" type="text/jscript"></script>
    <script language="JavaScript" src="http://www.cnblogs.com/js/auto_dep_emp.js" type="text/javascript"></script>
    <script language="JavaScript" src="http://www.cnblogs.com/js/utils.js" type="text/jscript"></script>
 <script language="JavaScript" src="/..../js/validator.js" type="text/jscript"></script>
 <script type="text/javascript" src="http://www.cnblogs.com/js/openwin.js"></script>
 
  <style type="text/css">
  
  html,body {width:100%;height:100%;margin:0px;padding:0px;overflow:hidden;}
  .Title { FONT-WEIGHT: bold; FONT-SIZE: 18px }
   
   A.f:link, A.f:visited , A.f:active {
    font-weight:bold;
    COLOR: #003366; TEXT-DECORATION: underline;
   }
   A.f:hover {
    font-weight:bold;
    COLOR: #003366; TEXT-DECORATION: underline;
   }
  #NavBar {display:block;position:absolute;left:0px;top:0px;width:100%;overflow:hidden; z-index:3; height:130px;}
  #Main {position:absolute;left:0px;top:34px;width:100%;overflow:auto;z-index:2;
                height: 12px;
            }
  #ToolBar {position:absolute;bottom:0px;right:0px;width:100%;height:30px;text-align:center;background:#CEDFF1;z-index:2;overflow:hidden;}
    </style>
    <script type="text/javascript">
     
   function CheckAll(oCheckbox)
      {
           var GridView1 = document.getElementById("<%=GridView1.ClientID %>");
           for(i = 1;i < GridView1.rows.length; i++)
           {
                GridView1.rows[i].cells[0].getElementsByTagName("INPUT")[0].checked = oCheckbox.checked;
           }
      }
    </script> 
 <script type="text/javascript">
  function openWinForAddDegree()
       {
            var URL;
            URL = 'iv_degree_add.aspx';
            window.openNewWin(URL,'AddDegreeInfo','600','200');
       }
       
    </script>
</head>
<body>
   <form id="TheForm" name="TheForm" runat="server" method="post">
 <input type="hidden" id="hddep" name="hddep" runat="server" value="" />
 <input type="hidden" id="hdemp" name="hdemp" runat="server" value="" />
 <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" EnableScriptGlobalization="true" EnableScriptLocalization="true"></asp:ScriptManager>
  
 <div id="NavBar">
  <div id="tabs1" class="tabs1">
  <ul>
   <li><a href="iv_degree.aspx" rel="dropmenu1_d"><span>学历</span></a></li>
   <li><a href="car_mstr.aspx"><span>应聘渠道</span></a></li>
   <li><a href="car_driver.aspx"><span>教育类型</span></a></li>
   <li><a href="car_miles_fee.aspx"><span>其它语言</span></a></li>
   <li><a href="car_oil.aspx"><span>职位类别</span></a></li>
   <li><a href="car_repair.aspx"><span>历史维修</span></a></li>
   <li><a href="car_use_his_all.aspx"><span>历史用车</span></a></li>
   <li><a href="car_audi_dep.aspx"><span>部门核准</span></a></li>
   <li><a href="car_audi_hr.aspx"><span>行政核准</span></a></li>
  </ul>
  </div>
  <br style="clear: left;" />
  <br class="IEonlybr" />
</div>
<div id="Main">
</div>
<div id="div1" style="position:absolute; top:20px; left:20px;">
        <table width="100%" border="0" cellspacing="0" cellpadding="2"
            style="margin-top: 40px; height: 58px;">
            <tr>
                <td height="26" colspan="3" style="border-bottom: 1px #CCCCCC dotted" align="left">
                    <span style="font-size: 12px; background-color: #CEDFF1; color: #003366; padding: 5px;
                        margin: 0px; font-weight: bold;">查询条件&nbsp;
                    </span>
                    名 称:<asp:TextBox ID="tbSearchTxt" runat="server" Width="80"></asp:TextBox>&nbsp;
                    <asp:Button ID="btnQry" runat="server" Text=" 查询 " CssClass="btn" OnClick="btnQry_Click" />
                    <font color="#0066FF">(双击修改每行)</font>
                </td>
            </tr>
        </table>
    </div>
<div id="gvlist" style="OVERFLOW:auto; width:100%; height:600px; position:absolute; top:130px;left:20px; text-align:center;">  
  <asp:GridView ID="GridView1" runat="server" SkinID="GridView1" AutoGenerateColumns="False" onrowdatabound="GridView1_RowDataBound" Width="100%" > 
           <Columns>
                   <asp:TemplateField HeaderStyle-Width="10px">
                        <HeaderTemplate>
                            <input id="Checkbox" type="checkbox" onClick="CheckAll(this)" runat="server" />
                        </HeaderTemplate>
                        <ItemTemplate>
                        <asp:CheckBox ID="ItemCheckBox" runat="server" />
                        </ItemTemplate>
                    <HeaderStyle Width="10px"></HeaderStyle>
                    </asp:TemplateField>   
                    <asp:BoundField DataField="code_code" HeaderText="值" />
                    <asp:BoundField DataField="code_name" HeaderText="名称" />
                    <asp:BoundField DataField="code_desc" HeaderText="描述信息" />
                   
            </Columns>
 </asp:GridView>
</div>
<div id="ToolBar">
   <table width="100%" border="0" cellspacing="0" cellpadding="0" bordercolor="#CEDFF1">
     <tr>
    <td height="30" align="left" valign="middle" style="padding-left:10px;">
     <input type="button" id="btnSysIntr" name="btnSysIntr" class="btn" value=" 系统说明 " />
    </td>
    <td align="right" style="padding-right:10px;" valign="middle">
                    <input type="button" id="btnAdd" name="btnAdd" value="新增" onclick="openWinForAddDegree();" class="btn" />
                    <asp:Button ID="btnDel" runat="server" Text=" 删除 " CssClass="btn" OnClick="btnDel_Click"  />
     <input type="button" id="btnBack" name="btnBack" class="btn" value=" 返回 " onclick="javascript:history.back();" />
    </td>
     </tr>
   </table>
</div>

</form>
</body>
</html>

2)后台aspx.cs页面

 

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using oa_congregate2008._Class;
using System.Data.SqlClient;
using System.IO;
using System.Text;


public partial class HRM_config_iv_degree : BaseClass
{

    public string constring = System.Configuration.ConfigurationSettings.AppSettings["eHRCONNECTIONSTRING"];
    public string strWhere = "code_field is Not Null";

    protected void Page_Load(object sender, EventArgs e)
    {
         Class_LoginJudge.IsLogin();
        if (!Page.IsPostBack)
        {
            ViewState["strWhere"] = strWhere;
            gvDataBind();
        }
    }
    protected void gvDataBind()
    {
        string sql = "select code_field, code_code,code_desc,code_name from  code_mstr where " + "code_field ='degree' and " + ViewState["strWhere"].ToString();
        DataTable dt = ExecuteBySQL(sql);

        if (dt.Rows.Count == 0)
        {
            dt.Rows.Add(dt.NewRow());
            this.GridView1.DataSource = dt;
            this.GridView1.DataBind();
            int columnCount = dt.Columns.Count;
            this.GridView1.Rows[0].Cells.Clear();
            this.GridView1.Rows[0].Cells.Add(new TableCell());
            this.GridView1.Columns[0].Visible = false;
            this.GridView1.Rows[0].Cells[0].ColumnSpan = columnCount + 1;
            this.GridView1.Rows[0].Cells[0].Text = "没有记录";
            this.GridView1.Rows[0].Cells[0].Style.Add("text-align", "center");
            this.GridView1.Rows[0].Cells[0].Style.Add("color", "red");
            this.GridView1.Rows[0].Attributes.Add("ondblclick", "return false;");

        }
        else
        {
            this.GridView1.DataKeyNames = new string[] { "code_field" };
            this.GridView1.DataSource = dt;
            this.GridView1.DataBind();

        }
        dt.Dispose();
    }
    /// GridView 绑定
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "color=this.style.backgroundColor;this.style.backgroundColor='#DFF4FD'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=color");
            e.Row.Attributes["style"] = "Cursor:hand";
            e.Row.Attributes.Add("ondblclick", "location.href = 'iv_degree_edit.aspx?id=" + DataBinder.Eval(e.Row.DataItem, "code_code").ToString() + "'");
        }
    }
    protected void btnQry_Click(object sender, EventArgs e)
    {

        if (this.tbSearchTxt.Text.Trim() != "" && this.tbSearchTxt.Text.Trim() != null)
        {
            strWhere += " and code_name like '" + this.tbSearchTxt.Text.Trim() + "%'";
        }
        ViewState["strWhere"] = strWhere;
        gvDataBind();
    }
    /// <summary>
    /// 删除
    /// </summary>
   
    protected void btnDel_Click(object sender, EventArgs e)
    {

   
        try
        {
            foreach (GridViewRow gvr in GridView1.Rows)
            {
                CheckBox ch = (CheckBox)gvr.FindControl("ItemCheckBox");
                if (ch.Checked)
                {
                    string id = gvr.Cells[1].Text.ToString();
                    ExecuteBySQLNoReturn("delete from code_mstr where code_field = 'degree' and code_code='"+id+"'");
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "js", "alert('提示:删除成功!');", true);

                }
            }
        }
        catch (Exception ex)
        {
            string errMessage = "";
            for (Exception tempException = ex; tempException != null; tempException = tempException.InnerException)
            {
                errMessage += tempException.Message + Environment.NewLine + Environment.NewLine;
            }
            Response.Write(errMessage);
        }
        gvDataBind();
    }

}
3)增加前台页面

 

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

<!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>
    <style type="text/css">
     html,body {width:100%;height:100%;margin:0px;padding:0px;overflow:hidden;}
     td
    {
     font-family:Arial, Helvetica, sans-serif;
  font-size:12px;
  color:#000000;
    } 
     .wind_btn
       {
           border:solid 1px #003C74;
           height:22px;
           padding:2px 3px;
           background-image:url(../images/win_btn.gif);
       }
 .win_table td{
  
  border-collapse:collapse;
 }
 .none{ display:none;}
    </style>
  
   
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table style="width:100%;">
            <tr>
                <td>
                    <asp:Label ID="lblName" runat="server" Text="名称:" ></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="tbName" runat="server" Width="100"></asp:TextBox>
                </td>
                <td>
                    <asp:Label ID="lblDesc" runat="server" Text="描述信息:"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="tbDescInfo" runat="server" Width="100"></asp:TextBox>
                </td>
            </tr>
            <tr>
            <td colspan="4" align="center">
                <asp:Button ID="btnSave" runat="server" Text="保存" onclick="btnSave_Click" />
            </td>
            </tr>
        </table>
   
    </div>
    </form>
</body>
</html>

4)增加后台页面

 

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class HRM_config_iv_degree_add :BaseClass
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string maxvalue = getMaxValue("code_mstr", "degree");
        ExecuteBySQLNoReturn("insert into code_mstr(code_field,code_desc,code_name,code_code) values('degree','" + this.tbDescInfo.Text.Trim() + "','" + this.tbName.Text.Trim() + "','" + maxvalue + "')");
        Response.Write("<script>window.opener.location.href=window.opener.location.href;</script>");
        MessageBox("保存成功");
    }
}

5)编辑前台页面

 

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

<!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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:Label ID="lblName" runat="server" Text="名称:"></asp:Label>
        <asp:TextBox ID="tbName" runat="server"></asp:TextBox>
        <asp:Label ID="lblDesc" runat="server" Text="描述:"></asp:Label>
        <asp:TextBox ID="tbDesc" runat="server"></asp:TextBox>
        <br />
        <asp:Button ID="btnEdit" runat="server" Text="修改" onclick="btnEdit_Click" />
    </div>
    </form>
</body>
</html>

6)编辑后台页面

 

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class HRM_config_iv_degree_edit :BaseClass
{
    string _id ;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            _id = Request.QueryString["id"].ToString().Trim();
            DataTable dt = ExecuteBySQL("select code_name,code_desc from code_mstr where code_field='degree' and  code_code ='" + _id+ "'");
            ViewState["ID"] = _id;
            this.tbName.Text = dt.Rows[0]["code_name"].ToString();
            this.tbDesc.Text = dt.Rows[0]["code_desc"].ToString();
        }
    }
    protected void btnEdit_Click(object sender, EventArgs e)
    {

        ExecuteBySQLNoReturn("update code_mstr set code_name ='" + this.tbName.Text.Trim() + "',code_desc ='" + this.tbDesc.Text.Trim() + "' where code_field ='degree' and code_code='" + ViewState["ID"] + "'");
        Server.Transfer("iv_degree.aspx");
        MessageBox("编辑成功");
    }
  
}

你可能感兴趣的:(模式)