具有经典ASP的FullCalender.io

时间:2019-02-06 10:22:48

标签: jquery sql-server asp-classic fullcalendar

我对这个问题表示歉意,但我只能使用有限的编码语言,因此,您是我的最后支持。请看下面

我想将完整的calendar.io集成到我公司的本地Intranet中,以向我的商店经理显示假期(大约800名),以便区域经理可以了解发生的情况和时间。

我有一个资源管理系统,可以让他们(商店经理)预订假期,每天在Python的帮助下(感谢硒)将其转储到我的本地服务器上

现在,我的想法是使用带有完整日历的Python建立简单的连接以读取我的dB中的事件-仅静态。

但是,我公司的本地网络服务器未安装Python,并且该公司认为由于非常的陈旧性,在其上安装任何内容都是一种风险。

好吧,很酷,第2步让我们使用包含的php文件读取json并每天在其中转储一个json文件,使用python和pandas每天设置工作流程并不那么困难。

哦,也没有php,我们 唯一可以使用的就是asp。不是asp.net,而是asp-classic!

所以我一直在玩弄从我的ms-sql服务器上用asp-classic构建基本的html页面。而且我已经能够创建从我的dB提取的动态页面(在安全的Intranet上)

请注意,我为一家相当大的公司工作,任何更改都需要花费很长时间,并且陷入政治困境,所以我不会在网络服务器上安装Python / php或任何东西。

我有一个ms-sql表,如下所示:

ID : Varchar(255)
Event Start : datetime
Event End : datetime
Area : int

我想使用类似下面的内容可以使我在html页面上生成事件:

Set gobjConn = Server.CreateObject("ADODB.Connection")
Set grs = Server.CreateObject("ADODB.Recordset")
gsConnect = "Driver={SQL Server};Server=Server;Database=mydb;uid=uid,pw=pw
gobjConn.Open gsConnect


    gsSQL = "SELECT ID,[Event Start], [Event End] FROM Events WHERE Area = '" & Area& "'"
Set grs = gobjConn.Execute(gsSQL)

区域号是一个查询字符串,我将在代码中进一步声明。

从这里开始,我不知道如何将其集成到Jquery Full Calender中。

    $(document).ready(function() {

    $('#calendar').fullCalendar({
      header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,agendaWeek,agendaDay,listWeek'
      },
      defaultDate: '2019-01-12',
      editable: true,
      navLinks: true, // can click day/week names to navigate views
      eventLimit: true, // allow "more" link when too many events
      events: {
        url: 'read_my_sql_dB_here',
        error: function() {
          $('#script-warning').show();
        }
      },
      loading: function(bool) {
        $('#loading').toggle(bool);
      }
    });

  });

很抱歉,对于较长的帖子,我想它最好是显式的而不是隐式的!也请保持温柔,直到昨天晚上,我仍然不知道什么是asp-classic,或者我是新手。

1 个答案:

答案 0 :(得分:4)

听起来像您需要使用经典asp生成JSON代码。有一些可用于经典ASP(see here)的JSON类,但是FullCalender.io所需的JSON代码看起来非常简单,仅使用response.write而不是使用类生成它会更容易。

尝试这样的事情...

events.asp:

<%

    Response.ContentType = "application/json"

    Dim gobjConn, grs, gsConnect, gsSQL, theData, r, Area

    ' if you're getting the area int from the querystring it's wise to
    ' check it's actually an int before inserting it into your SQL

    Area = request.QueryString("Area")

    if NOT isNumeric(Area) then
        Area = 1 ' set a default
        'response.End() ' or just use response.End() to stop the script
    else
        Area = int(Area)
    end if

    Set gobjConn = Server.CreateObject("ADODB.Connection")
    Set grs = Server.CreateObject("ADODB.Recordset")
    gsConnect = "Driver={SQL Server};Server=Server;Database=mydb;uid=uid,pw=pw"
    gobjConn.Open gsConnect

    gsSQL = "SELECT ID,[Event Start], [Event End] FROM Events WHERE Area = " & Area
    Set grs = gobjConn.Execute(gsSQL)

        if NOT grs.EOF then

            ' Use GetRows() to convert the recordset to to a 2D array

            theData = grs.getRows()

            ' start to build the JSON

            response.write "[" & VBcrlf

            for r = 0 to uBound(theData,2)

                ' loop through the events

                response.write "  {" & VBcrlf
                response.write "    ""id"": """ & theData(0,r) & """," & VBcrlf

                ' If you want to include a title you would need to escape the text:
                ' response.write "    ""title"": """ & JSONEncode(theData(3,r)) & """," & VBcrlf

                response.write "    ""start"": """ & theData(1,r) & """," & VBcrlf
                response.write "    ""end"": """ & theData(2,r) & """" & VBcrlf

                if r = uBound(theData,2) then
                    ' end of events, no comma
                    response.write "  }" & VBcrlf
                else
                    response.write "  }," & VBcrlf
                end if

            next

            response.write "]"

        else

            ' no events

        end if

    grs.close() : set grs = nothing ' close the recordset
    gobjConn.close() : set gobjConn = nothing ' close the connection


    ' Use this function to escape JSON text

    Function JSONEncode(ByVal val)
        val = Replace(val, "\", "\\")
        val = Replace(val, """", "\""")
        val = Replace(val, Chr(8), "\b")
        val = Replace(val, Chr(12), "\f")
        val = Replace(val, Chr(10), "\n")
        val = Replace(val, Chr(13), "\r")
        val = Replace(val, Chr(9), "\t")
        JSONEncode = Trim(val)
    End Function

%>

使用@lankymart链接的JSON class

<!--#include file = "jsonObject.class.asp" -->
<%

    Response.ContentType = "application/json"

    Dim gobjConn, grs, gsConnect, gsSQL, Area

    ' if you're getting the area int from the querystring it's wise to
    ' check it's actually an int before inserting it into your SQL

    Area = request.QueryString("Area")

    if NOT isNumeric(Area) then
        Area = 0 ' set a default
        'response.End() ' or just use response.End() to stop the script
    else
        Area = int(Area)
    end if

    Set gobjConn = Server.CreateObject("ADODB.Connection")
    Set grs = Server.CreateObject("ADODB.Recordset")
    gsConnect = "Driver={SQL Server};Server=Server;Database=mydb;uid=uid,pw=pw"
    gobjConn.Open gsConnect

    gsSQL = "SELECT ID,[Event Start], [Event End] FROM Events WHERE Area = " & Area
    Set grs = gobjConn.Execute(gsSQL)

        set JSON = New JSONarray

            JSON.LoadRecordset grs

            JSON.Write() 

        set JSON = nothing

    grs.close() : set grs = nothing ' close the recordset
    gobjConn.close() : set gobjConn = nothing ' close the connection

%>

在您的jQuery中:

  events: {
    url: 'events.asp',
    error: function() {
      $('#script-warning').show();
    }
  },