【问题标题】:FullCalender.io with classic ASP带有经典 ASP 的 FullCalender.io
【发布时间】:2019-02-06 10:22:47
【问题描述】:

对于这个问题,我深表歉意,但我可以使用的编码语言非常有限 - 因此,您是我最后的支持堡垒。请看下面

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

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

现在,我的想法是使用带有完整日历的 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 是什么(或现在是什么),而且我是一个新手编码器。

【问题讨论】:

    标签: jquery sql-server asp-classic fullcalendar


    【解决方案1】:

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

    试试这样的...

    事件.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();
        }
      },
    

    【讨论】:

    • 过去个人使用this class,因为它非常直观,并且允许直接从ADODB.Recordset 生成json输出。
    • @Datanovice 不建议采用硬编码路线,请考虑使用我列出的类,这使得从数据库查询中输出 JSON 变得轻而易举。
    • 我看过@Lankymart 链接的JSON 类,它非常好。我已经用另一个使用 JSON 类的代码示例更新了我的答案。 JSON 不写入文件,而是在经典 ASP 页面上输出。
    • 您需要下载它。是的,单独的页面,你只需要在 jQuery 中引用 events.asp 页面(全域或使用父路径)
    • Area 查询字符串需要传递给 events.asp 页面,如果它只传递给 HTML 页面,它不会做任何事情。您可以尝试使用 .asp 扩展名重命名您的 .html 页面,这将允许您在与 jquery 相同的页面上执行 asp 代码。在页面顶部重复用于检索区域查询字符串并验证它是数字的 asp 代码。然后在您的 jquery 中将 url 行更改为:url: 'path/to/events.asp?Area=&lt;%=Area%&gt;'
    猜你喜欢
    • 1970-01-01
    • 2011-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多