Code Management (2)

xiaoxiao2021-03-06  69

Imports system.data.sqlclient

Public Class Webform1

Inherits System.Web.ui.page

Private holiday as string = "" "

DIM FLAG AS INTEGER

Dim defarray () AS STRING

Dim SqlConnection1 As New SqlClient.SqlConnection ( "workstation id = 'NIIT-CF8DA03054'; packet size = 4096; user id = sa; data source = '.'; Persist security info = False; initial catalog = pubs")

'Dim SqldataAdapter1 as new Sqlclient.sqldataAdapter

Dim SqldataAdapter2 as new sqlclient.sqldataadapter

Dim DataSet1 As New DataSet

Dim Dataset2 As New DataSet

Private DT As New DataTable

Private Sub Page_Load (Byvale AS System.Object, Byval E AS System.Eventargs) Handles MyBase.LOAD

'Place the user code of the initialization page here

DIM INTYEAR AS INTEGER

DIM INTMONTH AS INTEGER

IF not me.ispostback then

'Calendar Show Current Date

Interedear = 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))

'' end

'Create a DataTable in Session

'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 datacolumnmydatacolumn.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)

'' end

'Define a session

Me.sqlConnection1.Open ()

Me.sqldataadapter1.selectcommand = new sqlclient.sqlcommand ("Select * from holiday", me.sqlconnection1)

Me.sqldataAdapter1.Fill (me.dataset1)

Me.sqlConnection1.close ()

Dt = me.dataset1.tables (0)

Session ("SelectDays") = DT

'' end

END IF

'Avoid the current date when the page is loaded

Me.calendar1.selectedDate = Nothing

End Sub

Private sub page_prender (byval e as system.eventargs) Handles mybase.prender

DT = ctype (session ("SelectDays"), DATATABLE)

'1) Only when there is no date on the calendar

If me.calendar1.selecteddate = Nothing Then

DIM SELSTR AS STRING

Dim Foundrows as DataRow ()

Selstr = "year = '" & me.ddlyear.selecteditem.value & "' and month = '" & me.ddlmonth.selectedItem.Value & "'"

FoundRows = DT.Select (Selstr)

'If there is no record in the database ---- get the default holiday setting, for example: 5, 6

If FOUNDROWS.LENGTH = 0 THEN

Me.holiday = me.getdefholidy (). Trim

'Generate arrays in strings

DEFARRAY = Split (Holiday, ",")

Flag = 1

END IF

END IF

'2) Only when you click on the date on the calendar

If not me.calendar1.selecteddate = Nothing then

Dim newrow as datarow = dt.newrow

Dim Eachrow As DataRow

'Query the session, whether the date already exists in the session, if the record is deleted; not add this record

For Each Eachrow in Dt.Rows

'There is this record to delete it

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

'Add it on this record

NEWROW.ITEM (0) = me.calendar1.selectedddate.Year

NEWROW.ITEM (1) = me.calendar1.selectedDate.month

NEWROW.ITEM (2) = me.calendar1.selectedddate.day

NEWROW.ITEM (3) = "1"

Dt.Rows.Add (newrow)

Session ("SelectDays") = DT

Flag = 0

END IF

End Sub

Private sub calendar1_dayrender (Byval e as system.web.ui.webcontrols.dayrendereventargs) Handles Calendar1.dayrender

'If the day is not the date of this month, it disables the 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

EXIT SUB

END IF

Else

If e.day.date.month <> me.calendar1.todaysdate.month Then

e.day.isselectable = false

E.cell.enabled = false

EXIT SUB

END IF

END IF

DT = ctype (session ("SelectDays"), DATATABLE)

'If there is no record in the database, get the default holiday setting

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

'' 'First put the date of the default holiday set into the session variable

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.day.day

NEWROW.ITEM (3) = "1"

Dt.Rows.Add (newrow)

END IF

NEXT

Session ("SelectDays") = DT

Else

'If there is a record of holiday settings in the database, read the value in the session.

DIM I as integerfor 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 BTN_SURE1_CLICK (Byvale AS System.Object, Byval E AS System.Eventargs) Handles BTN_SURE1.CLICK

If Me.ModifyHoliday () = 1 THEN

Page.RegisterStartupscript (","