根据输入参数,判定时间范围CheckTimeSpan

          对于C#的开发的网页程式,一些企业或者工厂可能会运用这些程式去查询一些资料,考虑到查询的资料太多,假如一个月的资料就有上万条数据,在对于查询资料的SQL语句后时间栏位运用Between.....AND......对查询时间范围进行控制,以免捞取数据太多,查询时间较长。

         根据判断输入的时间范围返回的结果是True或者FALSE来进行处理。已限制一个月(30天)的查询时间为例,代码如下:

 

 private bool CheckDateTimeScope()
        {
            DateTime FD = Convert.ToDateTime(Param.InForm.Value);
            DateTime ED = Convert.ToDateTime(Param.InEnd.Value);

            if (((TimeSpan)(ED - FD)).Days < 30)
            {
                return true;
            }
            else
            {
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alertForm", "alert('Start Date to End Date Must not Large than 30 days ! ');", true);
                return false;
            }
        }
posted @ 2020-01-02 14:33  码农阿亮  阅读(438)  评论(0编辑  收藏  举报