天天看点

新手测试题目的add.aspx与add.cs的内容。

add.aspx的内容:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="add.aspx.cs" Inherits="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>

    <link href="style.css" target="_blank" rel="external nofollow" rel="stylesheet" type="text/css" />

</head>

<body>

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

    <div>

        <table cellpadding="0" cellspacing="0" style="width: 760px; position: relative;

            text-align: center">

            <tr>

                <td style="height: 476px">

                    <table cellpadding="0" cellspacing="0" style="width: 100%; position: relative;

                        height: 94%; border-right: activeborder 1px solid; border-top: activeborder 1px solid; left: 0px; border-left: activeborder 1px solid; border-bottom: activeborder 1px solid; top: 0px;">

                        <tr>

                            <td colspan="2" style="font-weight: bold; color: red; height: 32px" align="left">

                                &nbsp;&nbsp;添加新记录</td>

                        </tr>

                        <tr>

                            <td style="width: 111px; text-align: right; height: 29px;">

                                &nbsp;项目名:</td>

                            <td style="text-align: left; height: 29px;">

                                <asp:TextBox ID="txtUserName" runat="server" Style="position: relative"></asp:TextBox></td>

                        </tr>

                        <tr>

                            <td style="width: 111px; text-align: right; height: 29px;">

                                客户:</td>

                            <td style="text-align: left; height: 29px;">

                                <asp:TextBox ID="txtcustomer" runat="server" Style="position: relative"></asp:TextBox>

                                </td>

                        </tr>

                        <tr>

                            <td style="width: 111px; text-align: right">

                                状态:</td>

                            <td style="text-align: left" height="29">

                                <asp:RadioButton ID="rbtnNv" runat="server"

                                    Checked="True" GroupName="sex" Style="position: relative" Text="完成" />

                                <asp:RadioButton ID="rbtnNan" runat="server"

                                    GroupName="sex" Style="position: relative" Text="进行中" /></td>

                        </tr>

                        <tr>

                            <td style="width: 111px; text-align: right; height: 29px;">

                                完成日期:</td>

                            <td style="text-align: left; height: 29px;">

                                <asp:TextBox ID="txtDate" runat="server" Style="position: relative"></asp:TextBox></td>

                        </tr>

                        <tr>

                            <td style="width: 111px; height: 15px; text-align: right">

                                描述:</td>

                            <td style="text-align: left" height="29">

                                <asp:TextBox ID="txtRemark" runat="server" Style="position: relative"></asp:TextBox></td>

                        </tr>

                        <tr>

                            <td style="width: 111px; height: 32px; text-align: right" valign="top">

                            </td>

                            <td style="height: 32px; text-align: left">

                                <asp:Button ID="Button1" runat="server" Style="position: relative" Text="添加" OnClick="Button1_Click" Width="51px" />

                                <asp:Button ID="Button2" runat="server" Style="position: relative" Text="清空" OnClick="Button2_Click" Width="52px" />

                                <asp:Button ID="Button3" runat="server" Style="position: relative" οnclick="Button3_Click" Text="返回" Width="52px" />

                            </td>

                        </tr>

                    </table>

                </td>

            </tr>

        </table>

    </div>

    </form>

</body>

</html>

add.cs的内容:

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

{

    protected void Page_Load(object sender, EventArgs e)

    {

    }

    protected void Button1_Click(object sender, EventArgs e)

    {

        string Staus;

        string ProjName = this.txtUserName.Text;

        string Customer = this.txtcustomer.Text;

        string CompleteDate = this.txtDate.Text;

        string Remark = this.txtRemark.Text;

        if (this.rbtnNv.Checked == true)

        {

            Staus = "true";

        }

        else

        {

            Staus = "false";

        }

        SqlConnection conn = DB.createCon();

        SqlCommand cmd = new SqlCommand();

        cmd.Connection = conn;

        cmd.CommandText = "insert into Prjinfo(ProjName,Customer,Staus,CompleteDate,Remark) values('" + ProjName + "','" + Customer + "','" + Staus + "','" + CompleteDate + "','" + Remark + "')";

        if (cmd.ExecuteNonQuery() > 0)

        {

            Response.Write("<script>alert('添加成功!');location.href='default.aspx';</script>");

        }

        else

        {

            Response.Write("<script>alert('添加失败!');window.location = window.location;</script>");

        }

    }

    protected void Button2_Click(object sender, EventArgs e)

    {

        this.txtUserName.Text = "";

        this.txtcustomer.Text = "";

        this.txtRemark.Text = "";

        this.txtDate.Text = "";

    }

    protected void Button3_Click(object sender, EventArgs e)

    {

        Response.Write("<script>location.href='default.aspx';</script>");

    }

}