2

我正在做的是创建一个 PDF 文件并返回本周的预订。周一、周四、周三等都有预订。我尝试将预订分配给他的日期。我的意思是。如果有星期一的预订,则应将预订分配到该日期。如果预订在星期二,则将星期四的预订分配给该日期。

为了说明这一点: WeeklyBPlan

正如您在 Montag(星期一)的图片预订和 Dienstag(星期二)的预订中看到的那样。

我的问题是,使用我的代码只返回一周的第一天(星期一),并且所有预订都分配给该日期。

我认为我的问题是wbp.WeekDay = strCurrDay或我的 .fo 有问题?

请问有人可以帮我吗?我怎样才能做我想做的事,比如图片中的?

Public Shared Function WeeklyBPlanPDFExport() As List(Of WeeklyBPlan)

        Dim allBookings As List(Of WeeklyBPlan) = New List(Of WeeklyBPlan)

        Dim s As StringBuilder = New StringBuilder
        Dim kw As Integer = DatePart(DateInterval.WeekOfYear, Now, , FirstWeekOfYear.FirstFourDays)
        If DatePart(DateInterval.Weekday, Now, Microsoft.VisualBasic.FirstDayOfWeek.Sunday) = 6 Then
            kw = kw + 1
        End If
        Dim CurrDateFirstDay As Date = DateAdd(DateInterval.Day, 1, ReturnDateForWeekNumber(kw))
        For i = 1 To 7
            Dim strCurrDay As String = ""

            strCurrDay = FormatDateTime(CurrDateFirstDay, DateFormat.LongDate)

            CurrDateFirstDay = DateAdd(DateInterval.Day, 1, CurrDateFirstDay)


            Dim strSQL As String = "SELECT  d.SEATING, d.ROOMID, d.ID, d.PERSONS, d.ADDRESS+ ', ' + d.ROOMDESCRIPTION AS ROOMDESCRIPTION , d.EVENT,  p.VN + ' ' + p.NN AS NAME, CONVERT (char(5), d.FROM, 108) + ' - ' + CONVERT (char(5), d.TO, 108) AS TIME, p.TEL FROM VIEW_RAUMBUCHUNG_DISPO AS d INNER JOIN PERSONAL AS p ON d.PERSONAL_ID = p.ID WHERE CONVERT(char, d.FROM, 104)='" & to_104(strCurrDay) & "'"
            Dim objRS As SqlDataReader
            Dim objRS2 As SqlDataReader
            objRS = SQLrunReaderWB(strSQL)

            If objRS.HasRows Then

                While objRS.Read()

                    Dim wbp = New WeeklyBPlan



                    wbp.WeekDay = strCurrDay

                    wbp.Raum = objRS("ROOMDESCRIPTION")
                    wbp.Zeit = objRS("TIME")



                    If Not IsDBNull(objRS("EVENT")) Then
                        wbp.Thema = objRS("EVENT")
                    End If

                    If Not IsDBNull(objRS("NAME")) Then
                        wbp.Mieter = objRS("NAME")
                    End If



                    wbp.Personen = objRS("PERSONS")
                    wbp.Bestuhlung = objRS("SEATING")



                    allBookings.Add(wbp)




                End While




            End If
        Next
        ConnWB.Close()

        Return allBookings


    End Function

我的 XSL-FO:

`

                 <!--this defines a title level 1 -->



                    <fo:block

                            line-height="24pt"
                            space-after.optimum="15pt"
                            padding-top="3pt">
                      <xsl:value-of select=".//WeekDay" />
                    </fo:block>


                <!-- table start -->
                <fo:table table-layout="fixed" border="solid" border-collapse="collapse" border-width="0.5pt">
                    <fo:table-column column-width="25mm"/>
                    <fo:table-column column-width="12mm"/>
                    <fo:table-column column-width="20mm"/>
                                <fo:table-column column-width="50mm"/>
                    <fo:table-column column-width="20mm"/>
                    <fo:table-column column-width="25mm"/>
                                <fo:table-column column-width="10mm"/>
                    <fo:table-column column-width="30mm"/>
                    <fo:table-column column-width="35mm"/>
                    <fo:table-column column-width="35mm"/>
                    <fo:table-header>
                        <fo:table-row>
                            <fo:table-cell>
                                <fo:block background-color="grey"
                      color="white" text-align="center">Room</fo:block>
                            </fo:table-cell>
                            <fo:table-cell>
                                <fo:block background-color="grey"
                      color="white" text-align="center">Time</fo:block>
                            </fo:table-cell>

                                            <fo:table-cell>
                                <fo:block background-color="grey"
                      color="white" text-align="center">Event</fo:block>
                            </fo:table-cell>

                                            <fo:table-cell>
                                <fo:block background-color="grey"
                      color="white" text-align="center">Persons</fo:block>
                            </fo:table-cell>
                           <fo:table-cell>
                            <fo:block background-color="grey"
                      color="white" text-align="center">Seating</fo:block>
                           </fo:table-cell>

                           </fo:table-row>
                      <fo:table-row>
                      </fo:table-row>
                    </fo:table-header>
                    <fo:table-body>
                      <xsl:for-each select=".//WochenBPlan">
                            <fo:table-row>
                                <fo:table-cell  border-right-width="0.5pt" border-right-style="solid"  border-bottom-width="0.5pt" border-bottom-style="solid" padding-right="6pt" padding-left="6pt" >
                                    <fo:block font-family="Arial" font-size="9pt"  padding="2pt">
                                        <xsl:value-of select=".//Room" />
                                    </fo:block>
                                </fo:table-cell>
                                <fo:table-cell border-right-width="0.5pt" border-right-style="solid" border-bottom-width="0.5pt" border-bottom-style="solid">
                                    <fo:block font-family="Arial" font-size="9pt"  padding="2pt"  text-align="center">
                                        <xsl:value-of select=".//Time" />
                                    </fo:block>
                                </fo:table-cell>

                                <fo:table-cell border-right-width="0.5pt" border-right-style="solid"  border-bottom-width="0.5pt" border-bottom-style="solid" padding-left="6pt" padding-right="6pt">

                                       <fo:block font-family="Arial" font-size="9pt"  padding="2pt" wrap-option="no-wrap" >
                                        <xsl:value-of select=".//Event" />
                                       </fo:block>

                                </fo:table-cell>


                              <fo:table-cell border-right-width="0.5pt" border-right-style="solid" border-bottom-width="0.5pt" border-bottom-style="solid">
                                <fo:block font-family="Arial" font-size="9pt"  padding="2pt" text-align="center">
                                  <xsl:value-of select=".//Persons" />
                                </fo:block>
                              </fo:table-cell>
                              <fo:table-cell border-right-width="0.5pt" border-right-style="solid" border-bottom-width="0.5pt" border-bottom-style="solid"> 
                                <fo:block  font-family="Arial" font-size="9pt" padding="2pt" text-align="center">
                                  <xsl:value-of select=".//Seating" />
                                </fo:block>
                              </fo:table-cell>


                              </fo:table-row>

                      </xsl:for-each>
                    </fo:table-body>
                  </fo:table>
                  <!-- table end -->




                <fo:block id="lastBlock"/>
            </fo:flow>`

WeeklylyBPlan 课程:

public class WochenBPlan
{
    public WochenBPlan()
    {

    }

    public string Raum { get; set; }
    public DateTime Erstellt { get { return DateTime.Now; } set { } }
    public string Zeit { get; set; }
    public string Bereich { get; set; }
    public string Thema { get; set; }
    public string Mieter { get; set; }
    public string Mieter_Tel { get; set; }
    public string Personen { get; set; }
    public string Bestuhlung { get; set; }
    public string Bemerkung { get; set; }
    public string Ausstattung { get; set; }
    public string WochenTag { get; set; }



}
4

1 回答 1

0

好吧,老实说,我没有太多编写 C# 的经验,所以我现在将用 VB 编写你的 WochenBPlan 类,只是为了让你暂时免于阅读我的 C# 的痛苦。

附带说明一下,鉴于您的类实际上只是一个结构,因为它没有任何真正与之关联的功能,您可以将其转换为公共结构,但它是所有偏好。

困扰我的是您正在声明一个新的 WeeklyBPlan 但我认为为了清晰和简单起见,您可能应该编写一些“新”子程序,例如...

     Public Class WochenBPlan 
      'I've learn that it is best to declare class variables private and then expose them through public properties as follows
       Private _Raum As String, _Zeit As String, _Bereich As String, _Thema As String
       Private _Mieter As String, _Mieter_Tel As String, _Personen As String
       Private _Bestuhlung As String, _Bemerkung As String, _Ausstattung As String
       Private _WochenTag As String, _Erstellt As DateTime

       Public Property Raum As String
         Get
            Return _Raum
         End Get
         Set(value As String)
           _Raum = value
         End Set
        End Property
       ' So on and so forth for the remaining....

      ' Adding some functionality

      ' Default Constructor
      Public Sub New()
       ' Set all private variables to what you want (I tend to set them to Nothing, unless I need them to be some value)
      End Sub


      Public Sub New(ByVal theDay As String, ByVal theRoom As String, ByVal theTime As String(I'm not sure what type you have that has), ByVal thePersons As String, ByVal theSeating As String)
     _WeekDay(Or the German word for it) = theDay
     _Raum = theRoom
     _Zeit = theTime
     _Personen = thePersons
     _Bestuhlung = theSeating
     ' Declare rest to nothing/null
     End Sub
    ' Add Whatever Else You May Want
      End Class

这将确保您在每个循环中设置好所有内容,然后您的第二个循环将简化为...

         While objRS.Read()

                Dim wbp = New WeeklyBPlan(strCurrDay, objRS("ROOMDESCRIPTION"), objRS("TIME"),objRS("PERSONS"))


                If Not IsDBNull(objRS("EVENT")) Then
                    wbp.Thema = objRS("EVENT")
                End If

                If Not IsDBNull(objRS("NAME")) Then
                    wbp.Mieter = objRS("NAME")
                End If




                allBookings.Add(wbp)




            End While

我不确定这是否会奏效,但它很可能,所以让我知道是否有效,否则我将继续工作,直到我们弄明白为止。您可以将这些“If”语句添加到重载的“New”语句中,然后您可以执行 allBookings.Add(New WeeklyBPlan(...))

于 2012-12-24T06:39:48.540 回答