如何分配List的值

时间:2012-12-23 13:43:00

标签: vb.net xsl-fo

我正在做的是创建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

MY 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>`

WeekylyBPlan课程:

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; }



}

1 个答案:

答案 0 :(得分: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(...))