Пример #1
0
        public void ProcessRequest(HttpContext context)
        {
            BLL.HKSJ_Main mainService = new BLL.HKSJ_Main();

            context.Response.ContentType = "text/plain";

            Model.HKSJ_Main newsInfo = new Model.HKSJ_Main();

            newsInfo.ID      = context.Request["ID"] == null ? 0 : Convert.ToInt32(context.Request["ID"]);
            newsInfo.title   = context.Request["title"];
            newsInfo.content = context.Request["content"];
            newsInfo.Date    = Convert.ToDateTime(context.Request["Date"]);
            newsInfo.type    = context.Request["type"];
            newsInfo.people  = context.Request["people"];
            newsInfo.picUrl  = context.Request["picUrl"];

            if (mainService.Update(newsInfo))
            {
                context.Response.Write("OK");
            }
            else
            {
                context.Response.Write("error");
            }
        }
Пример #2
0
        public void ProcessRequest(HttpContext context)
        {
            BLL.HKSJ_Main mainService = new BLL.HKSJ_Main();
            context.Response.ContentType = "text/plain";

            Model.HKSJ_Main newsInfo = new Model.HKSJ_Main();

            newsInfo.title   = context.Request["title"] == null ? string.Empty : context.Request["title"];
            newsInfo.content = context.Request["content"] == null ? string.Empty : context.Request["content"];
            newsInfo.Date    = Convert.ToDateTime(context.Request["Date"]);

            //这里不能限制读取的值
            newsInfo.type   = string.Format("{0}", "1       ");
            newsInfo.people = context.Request["people"] == null?string.Format("{0}", "Unknow") : context.Request["people"];

            newsInfo.picUrl = context.Request["picUrl"] == null ? string.Empty : context.Request["picUrl"];

            if (mainService.Add(newsInfo) > 0)
            {
                context.Response.Write("OK");
            }
            else
            {
                context.Response.Write("error");
            }
        }
Пример #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int ID = Request["ID"] == null ? 0 : Convert.ToInt32(Request["ID"]);

            //获取ID的新闻显示在页面上面
            BLL.HKSJ_Main mainServices = new BLL.HKSJ_Main();
            mainShowInfo = mainServices.GetModel(ID);
        }
Пример #4
0
        //使用存储过程进行分页,
        public List <Model.HKSJ_Main> GetPageSizeNav(int pageSize, int pageIndex, out int totalCount)
        {
            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString))
                {
                    adapter.SelectCommand = conn.CreateCommand();

                    adapter.SelectCommand.CommandText = "Pro_GetPageProject";
                    adapter.SelectCommand.CommandType = CommandType.StoredProcedure;//设置执行一个存储过程


                    adapter.SelectCommand.Parameters.Add(new SqlParameter("@pageIndex", pageIndex));
                    adapter.SelectCommand.Parameters.Add(new SqlParameter("@pageSize", pageSize));

                    //设置一个输出参数
                    SqlParameter parameterTotalCount = new SqlParameter("@totalCount", SqlDbType.Int);
                    parameterTotalCount.Direction = ParameterDirection.Output;//代表输出参数

                    adapter.SelectCommand.Parameters.Add(parameterTotalCount);



                    DataSet ds = new DataSet();

                    adapter.Fill(ds);//自动打开连接,自动读取数据放到表里去,另外自动释放Reader..

                    //获取一共有多少条[第一种方式获取返回值的参数]
                    totalCount = int.Parse(ds.Tables[1].Rows[0][0].ToString());

                    //第二种获取返回值参数的方式:直接从输出参数获取值
                    totalCount = (int)parameterTotalCount.Value;//如果使用的是SqlDataReader读取数据的话,必须等待
                    //Reader释放之后才能拿到 输出参数的值。


                    List <Model.HKSJ_Main> projects = new List <Model.HKSJ_Main>();
                    //获取数据分页数据
                    foreach (DataRow row in ds.Tables[0].Rows)
                    {
                        Model.HKSJ_Main projectInfo = new Model.HKSJ_Main();
                        projectInfo.ID      = int.Parse(row["ID"].ToString());
                        projectInfo.content = row["content"] == DBNull.Value ? string.Empty : row["content"].ToString();
                        projectInfo.title   = row["title"] == DBNull.Value ? string.Empty : row["title"].ToString();
                        projectInfo.type    = row["type"] == DBNull.Value ? string.Empty : row["type"].ToString();
                        projectInfo.picUrl  = row["picUrl"] == DBNull.Value ? string.Empty : row["picUrl"].ToString();
                        projectInfo.Date    = row["Date"] == DBNull.Value ? DateTime.Now : (DateTime)row["Date"];
                        projectInfo.people  = row["people"] == DBNull.Value ? string.Empty : row["people"].ToString();


                        projects.Add(projectInfo);
                    }

                    return(projects);
                }
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (IsPostBack)
     {
         BLL.HKSJ_Main mainBll = new BLL.HKSJ_Main();
         Model.HKSJ_Main newsModel = new Model.HKSJ_Main();
         //获得新闻数据
         newsModel.title = Context.Request["title"];
         newsModel.picUrl = "";
         newsModel.people = "";
         newsModel.Date = DateTime.Now;
         newsModel.type = "";
         newsModel.content = Context.Request["content"];
         //保存到数据库
         mainBll.Add(newsModel);
         //重定向
         Context.Response.Redirect("ShowListForm.aspx");
     }
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     int id = int.Parse(Context.Request["id"]??"0");
     BLL.HKSJ_Main mainBll = new BLL.HKSJ_Main();
     NewsDeatail=mainBll.GetModel(id);
 }