zoukankan      html  css  js  c++  java
  • 04Add.ashx(新增班级)

    04Add.html

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title>新增班级</title>
        <style type="text/css">
            #tbList {
                border:1px solid #0094ff;
                border-collapse:collapse;
                300px;
                margin:50px auto;
            }
            #tbList th,td{
                border:1px solid #0094ff;
                padding:5px;
            }
        </style>
    </head>
    <body>
        <form method="post" action="04Add.ashx">
            <table id="tbList">
                <tr>
                    <td>班级名称:</td>
                    <td><input type="text" id="txtName" name="txtName"/></td>
                </tr>
                <tr>
                    <td>班级人数:</td>
                    <td><input type="text" id="txtCount" name="txtCount" /></td>
                </tr>
                <tr>
                    <td colspan="2">
                        <input type="submit" value="确定" />
                        <input type="button" id="btnCancel" value="取消" onclick="window.location='01List.ashx'" />
                    </td>
                </tr>
            </table>
        </form>
    </body>
    </html>

    04Add.ashx

    using System;
    using System.Collections.Generic;
    using System.Data.SqlClient;
    using System.Linq;
    using System.Web;
    
    namespace AspNetAshx
    {
        /// <summary>
        /// _04Add 的摘要说明
        /// </summary>
        public class _04Add : IHttpHandler
        {
    
            public void ProcessRequest(HttpContext context)
            {
                context.Response.ContentType = "text/html";
    
                //1.获取用户表单post提交的数据
                string strName = HttpContext.Current.Request.Form["txtName"].Trim();
                string strCount = HttpContext.Current.Request.Form["txtCount"];
                //2.验证数据
                if (string.IsNullOrEmpty(strName) || !CommonHelper.IsNum(strCount))
                {
                    CommonHelper.WriteJs("对不起,您输入的数据格式错误~请仔细检查~~", "04Add.html");
                }
                else
                {
                    //3.更新到数据库中
                    SqlParameter[] paras = { 
                                       new SqlParameter("Cname",strName),
                                       new SqlParameter("CCount",strCount)
                                       };
                    int res = SqlHelper.ExcuteNoneQuery("insert into Classes (CName,CCount) values(@Cname,@CCount)", paras);
                    if (res > 0)
                    {
                        CommonHelper.WriteJs("新增成功~!", "01List.ashx");
                    }
                    else
                    {
                        CommonHelper.WriteJs("新增失败~!如果您是美女,请联系管理员~~~qq:111111", "04Add.html");
                    }
                }
            }
    
            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }
    }
  • 相关阅读:
    java小白学习练手成绩管理系统(一)
    java初级学习练手成绩管理系统(四)
    Echart可视化学习集合
    java小白学习练手成绩管理系统(六)
    java小白学习练手成绩管理系统
    网页内容加密
    Ubuntu 10.04 安装配置指南
    Linux目录解释
    完整清除XP垃圾文件系统自带的秘密武器
    人人都应该掌握的一些电脑操作技巧
  • 原文地址:https://www.cnblogs.com/hehehehehe/p/5105899.html
Copyright © 2011-2022 走看看