CSDN博客

img huanghui22

77777

发表于2004/9/30 12:01:00  1431人阅读

Imports CyberRS2.APS.BusinessFacade
Imports CyberRS2.APS.Model
Imports CyberRS2.APS.SysCommon
Imports cyberrs2.APS.BusinessFacade.HolidayFacade

 


Public Class ManageHolidaySet
    Inherits System.Web.UI.Page
    Protected WithEvents Calendar1 As System.Web.UI.WebControls.Calendar

    Protected WithEvents TD1 As System.Web.UI.HtmlControls.HtmlTableCell
    Protected WithEvents TD2 As System.Web.UI.HtmlControls.HtmlTableCell
    Protected WithEvents TD3 As System.Web.UI.HtmlControls.HtmlTableCell
    Protected WithEvents TD4 As System.Web.UI.HtmlControls.HtmlTableCell


    Protected WithEvents ddlYear As System.Web.UI.WebControls.DropDownList
    Protected WithEvents ddlMonth As System.Web.UI.WebControls.DropDownList
    Protected WithEvents btn_sure1 As System.Web.UI.WebControls.ImageButton
    Protected WithEvents btn_dfhdset1 As System.Web.UI.WebControls.ImageButton
    Protected WithEvents btn_restore1 As System.Web.UI.WebControls.ImageButton

#Region " Web 窗体设计器生成的代码 "

    '该调用是 Web 窗体设计器所必需的。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
        '不要使用代码编辑器修改它。
        InitializeComponent()
    End Sub

#End Region
    Private holiday As String = ""
    Dim defarray() As String
    Private dt As New DataTable()
    Dim flag As Integer


    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '在此处放置初始化页的用户代码
        Dim intyear As Integer
        Dim intmonth As Integer

        If Not Me.IsPostBack Then
            intyear = Now.Year()
            intmonth = Now.Month()
            ''''''''''''''''''''''''''''''''''''''
            Me.ddlYear.SelectedIndex = Me.ddlYear.Items.IndexOf(Me.ddlYear.Items.FindByValue(intyear.ToString))
            Me.ddlMonth.SelectedIndex = Me.ddlMonth.Items.IndexOf(Me.ddlMonth.Items.FindByValue(intmonth.ToString))

            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            ' Declare DataColumn and DataRow variables.
            Dim myDataColumn As DataColumn
            Dim myDataRow As DataRow

            ' Create new DataColumn, set DataType, ColumnName and add to DataTable.   
            myDataColumn = New DataColumn()
            myDataColumn.DataType = System.Type.GetType("System.String")
            myDataColumn.ColumnName = "Year"
            dt.Columns.Add(myDataColumn)

            ' Create second column.
            myDataColumn = New DataColumn()
            myDataColumn.DataType = Type.GetType("System.String")
            myDataColumn.ColumnName = "Month"
            dt.Columns.Add(myDataColumn)

            ' Create three column.
            myDataColumn = New DataColumn()
            myDataColumn.DataType = Type.GetType("System.String")
            myDataColumn.ColumnName = "Day"
            dt.Columns.Add(myDataColumn)

            ' Create four column.
            myDataColumn = New DataColumn()
            myDataColumn.DataType = Type.GetType("System.String")
            myDataColumn.ColumnName = "flag"
            dt.Columns.Add(myDataColumn)

            '定义一个Session
            Session("SelectDays") = dt
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        End If
        Me.Calendar1.SelectedDate = Nothing
    End Sub

 

    Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
        dt = CType(Session("SelectDays"), DataTable)
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        '只有当点击了日历上的日期时才实现
        If Not Me.Calendar1.SelectedDate = Nothing Then
            Dim newrow As DataRow = dt.NewRow
            Dim eachrow As DataRow

            '查询session,该日期是否已经存在于session中,如果在则删除该条记录;不在则添加该条记录
            For Each eachrow In dt.Rows
                '有这条记录就删除它
                If eachrow.Item(0) = Me.Calendar1.SelectedDate.Year And eachrow.Item(1) = Me.Calendar1.SelectedDate.Month And eachrow.Item(2) = Me.Calendar1.SelectedDate.Day Then
                    dt.Rows.Remove(eachrow)

                    Session("SelectDays") = dt
                    flag = 0
                    Exit Sub
                End If
            Next
            '没有这条记录就添加它
            newrow.Item(0) = Me.Calendar1.SelectedDate.Year
            newrow.Item(1) = Me.Calendar1.SelectedDate.Month
            newrow.Item(2) = Me.Calendar1.SelectedDate.Day

            dt.Rows.Add(newrow)
            Session("SelectDays") = dt
            flag = 0
        End If

        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        '没有点击了日历上的日期,实现下列代码
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        '1.1  页面导入时实现,当这个月没有设置过假日时使用默认设置,session为空;否则使用数据库中的记录,session中为数据库中的记录
        '2.1  当dropdownlist改变时,也需要实现,当新选择的月没有设置过假日时使用默认设置,session不变;否则使用数据库中的记录,把数据库中的记录添加如session中

        '得到当前显示月的假日设置
        If Me.Calendar1.SelectedDate = Nothing Then
            Dim selstr As String
            Dim dtHoliday As DataTable
            selstr = "select * from sys_holiday where year='" & Me.ddlYear.SelectedItem.Value & "'and month='" & Me.ddlMonth.SelectedItem.Value & "'"
            dtHoliday = HolidayFacade.GetMonthHoliday(selstr)

 

            dt = CType(Session("SelectDays"), DataTable)
            ' If Me.isMonthChange = True Then
            '如果数据库中没有假日设定的纪录
            If dtHoliday.Rows.Count = 0 Then
                '得到默认的假日设定
                '例如:5,6

                HolidayFacade.GetDefHolidy(holiday)
                '将字符串生成数组
                defarray = Split(holiday, ",")
                flag = 1
            End If
            If dtHoliday.Rows.Count <> 0 Then
                If dt.Rows.Count <> dtHoliday.Rows.Count Then

                    '如果数据库中有假日设定的纪录
                    '则把数据库中的假日添加到Session中
                    Dim eachrow As DataRow
                    For Each eachrow In dtHoliday.Rows()
                        dt.ImportRow(eachrow)
                    Next
                    Session("SelectDays") = dt
                    flag = 0
                Else
                    Session("SelectDays") = dt
                    flag = 0
                End If
            End If
        End If
    End Sub

 

 


    Private Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender

        '如果不是这个月里的日期的天,则禁用该日期的Enabled,IsSelectable
        If Me.Calendar1.VisibleDate <> Nothing Then
            If e.Day.Date.Month <> Me.Calendar1.VisibleDate.Month Then
                e.Day.IsSelectable = False
                e.Cell.Enabled = False
            End If
        Else
            If e.Day.Date.Month <> Me.Calendar1.TodaysDate.Month Then
                e.Day.IsSelectable = False
                e.Cell.Enabled = False
            End If
        End If

        '使被选中的日期变成红色的字体

        dt = CType(Session("SelectDays"), DataTable)
        '如果数据库中没有假日设定的纪录,得到默认的假日设定
        If flag = 1 Then
            Dim str As String
            For Each str In Me.defarray
                If e.Day.Date.DayOfWeek = Integer.Parse(str) Then
                    e.Cell.ForeColor = System.Drawing.Color.Red

                    '''先将默认假日设定的日期放入session变量中

                    'Dim newrow As DataRow = dt.NewRow

                    'newrow.Item(0) = e.Day.Date.Year
                    'newrow.Item(1) = e.Day.Date.Month
                    'newrow.Item(2) = e.Day.Date.Day
                    'dt.ImportRow(newrow)
                    Session("SelectDays") = dt
                End If
            Next
            '如果数据库中有假日设定的纪录,读session中的值
        ElseIf flag = 0 Then
            Dim i As Integer
            dt = CType(Session("SelectDays"), DataTable)
            For i = 0 To dt.Rows.Count - 1
                If e.Day.Date.Year = dt.Rows.Item(i).Item(0) And e.Day.Date.Month = dt.Rows.Item(i).Item(1) And e.Day.Date.Day = dt.Rows.Item(i).Item(2) Then
                    e.Cell.ForeColor = System.Drawing.Color.Red
                End If
            Next
        End If
    End Sub


    Private Sub Calendar1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged

    End Sub

    Private Sub btn_sure1_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btn_sure1.Click
        dt = CType(Session("SelectDays"), DataTable)
        Dim content As String
        Dim myMsgCode As New CyberRS2.APS.BusinessFacade.MsgCodeFacade()
        If Integer.Parse(HolidayFacade.ModifyHoliday(dt)) = 1 Then
            content = myMsgCode.GetMsg("MUF11001", WebUIConfig.CurrentLanguage)
            Page.RegisterStartupScript("", "<script language='javascript'>alert('" & content & "')</script>")
            '''''''''
            'dt.Clear()
            Session("SelectDays") = dt
            '''''''''
            Return
        Else
            content = myMsgCode.GetMsg("MUF11002", WebUIConfig.CurrentLanguage)
            Page.RegisterStartupScript("", "<script language='javascript'>alert('" & content & "')</script>")
            Return
        End If
    End Sub

    Private Sub ddlYear_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlYear.SelectedIndexChanged
        dt = CType(Session("SelectDays"), DataTable)
        dt.Clear()
        Session("SelectDays") = dt
        Me.Calendar1.VisibleDate = New DateTime(Integer.Parse(Me.ddlYear.SelectedItem.Value), Integer.Parse(Me.ddlMonth.SelectedItem.Value), 1)
    End Sub

    Private Sub ddlMonth_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlMonth.SelectedIndexChanged
        dt = CType(Session("SelectDays"), DataTable)
        dt.Clear()
        Session("SelectDays") = dt
        Me.Calendar1.VisibleDate = New DateTime(Integer.Parse(Me.ddlYear.SelectedItem.Value), Integer.Parse(Me.ddlMonth.SelectedItem.Value), 1)
    End Sub

    Private Sub btn_restore1_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btn_restore1.Click
        Dim year As String = Me.ddlYear.SelectedItem.Value
        Dim month As String = Me.ddlMonth.SelectedItem.Value
        If HolidayFacade.RestoreDefHoliday(year, month) = 1 Then
            dt = CType(Session("SelectDays"), DataTable)
            Dim i As Integer
            '删除session中的该月记录

       
            '查询session,查询属于该月的记录是否已经存在于session中,如果在则删除该条记录
           
            i = dt.Rows.Count
            While i <> 0
                If dt.Rows.Item(i - 1).Item(0) = year And dt.Rows.Item(i - 1)(1) = month Then
                    dt.Rows.Remove(dt.Rows.Item(i - 1))
                    i = i - 1
                End If
            End While


            Session("SelectDays") = dt

        End If
    End Sub

    Private Sub btn_dfhdset1_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btn_dfhdset1.Click
        Me.RegisterStartupScript("Open1", "<script language='javascript'>window.open('../SysAdmin/DefHolidaySet.aspx?');</script>")
    End Sub
End Class

 

 

 

 


 

阅读全文
0 0

相关文章推荐

img
取 消
img