コード例 #1
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/html";
            int id;

            if (int.TryParse(context.Request.QueryString["id"], out id))
            {
                ManagerInfoBLL miBLL       = new ManagerInfoBLL();
                ManagerInfo    managerInfo = miBLL.GetManagerInfo(id);
                if (managerInfo != null)
                {
                    string filePath    = context.Request.MapPath("ShowEditManagerInfo.html");
                    string fileContent = File.ReadAllText(filePath);
                    fileContent = fileContent.Replace("$MName", managerInfo.MName)
                                  .Replace("$MPwd", managerInfo.MPwd)
                                  .Replace("$MType", managerInfo.MType.ToString())
                                  .Replace("$id", managerInfo.MId.ToString());

                    context.Response.Write(fileContent);
                }
                else
                {
                    context.Response.Write("查无此人");
                }
            }
        }
コード例 #2
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            //string txtName = context.Request.Form["txtName"];
            //string txtPwd = context.Request.Form["txtPwd"];
            //int txtType = Convert.ToInt32(context.Request.Form["txtType"]);

            ////注意接受隐藏域中的id
            //int id = Convert.ToInt32(context.Request.Form["txtid"]);


            //ManagerInfo managerInfo = new ManagerInfo()
            //{
            //    MName = txtName,
            //    MPwd = txtPwd,
            //    MType = txtType,
            //    MId = id
            //};

            ////接收表单数据直接实例化为对象
            //ManagerInfo managerInfo = new ManagerInfo()
            //{
            //    MName =context.Request.Form["txtName"],
            //    MPwd = context.Request.Form["txtPwd"],
            //    MType = Convert.ToInt32(context.Request.Form["txtType"]),
            //    MId = Convert.ToInt32(context.Request.Form["txtid"])
            //};
            ///注意上面这种方式也是有缺陷的
            ///如果你的表中有很多列,但这些列是没有展示在Form 中,
            ///所以你实例化这个对象时,有些列是没有赋值数据的
            ///但是在Dal层中,你使用sql语句更新是更新的所有列,
            ///所以这里我们先使用id查询出数据库表的数据对象(我们之前已经封装了这个函数)
            ///在使用表单中的数据进行修改,这样如果表单中没有那一列数据,或是没有修改则就是用依旧是原来的数据
            ///

            int            id          = Convert.ToInt32(context.Request.Form["txtid"]);
            ManagerInfoBLL miBLL       = new ManagerInfoBLL();
            ManagerInfo    managerInfo = miBLL.GetManagerInfo(id);

            managerInfo.MName = context.Request.Form["txtName"];
            managerInfo.MPwd  = context.Request.Form["txtPwd"];
            managerInfo.MType = Convert.ToInt32(context.Request.Form["txtType"]);


            if (miBLL.EditManagerInfo(managerInfo))
            {
                context.Response.Redirect("ManagerInfoList.ashx");
            }
            else
            {
                context.Response.Redirect("Error.html");
            }
        }
コード例 #3
0
        /// <summary>
        /// 展示要修改的用户的信息
        /// </summary>
        private void ShowEditManagerInfo()
        {
            int id;

            if (int.TryParse(Request.QueryString["id"], out id))
            {
                ManagerInfoBLL miBLL = new ManagerInfoBLL();
                if (miBLL.GetManagerInfo(id) != null)//一定要做这个判断
                {
                    managerInfo = miBLL.GetManagerInfo(id);
                }
                else
                {
                    Response.Write("编辑对象id错误!");
                }
            }
            else
            {
                Response.Redirect("../CRUD/Error.html");
            }
        }