使用者又要新增功能〜假若有20堂课〜使用者设定起始时间为2017/06/16〜
课程完毕日期则为2017/08/11〜
每堂课阅读期限自动以两日往后累计〜并忽略六日〜
因为使用者懒....
还好在网路有看到一段适用的代码
程序代码:
Protected Sub btnQuery_Click(sender As Object, e As System.EventArgs) Handles btnQuery.Click
Dim FileNo1 As String = "", FileNo2 As Integer = 0, FileNo3 As Integer = 0
Dim ClassName = ""
Dim mySQL As String = ""
Dim UserN As String = Mid(Mid(UserNo.Text, InStr(UserNo.Text, "(") + 1), 1, Len(Mid(UserNo.Text, InStr(UserNo.Text, "(") + 1)) - 1)
Dim strMsg As String = ""
Dim TempTime() As String
Dim ST As String = ""
Dim ET As String = ""
Try
For i = 0 To ClassNo.Items.Count - 1
If ClassNo.Items(i).Value <> "" Then
ClassName = Mid(ClassNo.Items(i).Value, InStr(ClassNo.Items(i).Value, " ") + 1)
mySQL = "SELECT SubjectNo, SubFolderNo, FileNo FROM tblFileList Where FileName = '" & ClassName & "'"
Using mySqlDS = New SqlConnection(ConfigurationManager.ConnectionStrings(strCnnType & "DbBTA").ToString)
Dim myCmd As SqlCommand
myCmd = New SqlCommand(mySQL, mySqlDS)
mySqlDS.Open()
Using dbDRSQL = myCmd.ExecuteReader
While dbDRSQL.Read
FileNo1 = dbDRSQL("SubjectNo").ToString
FileNo2 = dbDRSQL("SubFolderNo").ToString
FileNo3 = dbDRSQL("FileNo").ToString
End While
End Using
End Using
If i = 1 Then
TempTime = Split(starttime.Text, "-")
Else
TempTime = Split(ST, "/")
End If
ST = New DateTime(CInt(TempTime(0)), CInt(TempTime(1)), CInt(TempTime(2)))
ET = DTAdd(ST, (1 * 2)).ToShortDateString()
Using myCnn As New SqlConnection(ConfigurationManager.ConnectionStrings(strCnnType & "DbBTA").ToString)
myCnn.Open()
Dim myCmd As SqlCommand
mySQL = "INSERT INTO tblSelectClass(UserID, ClassID, SubClassID, FileNo, StartDate, EndDate, StudyTime, StudyCount, StudyDate, Results, CreatorNo, CreateDate, ReviserNo, ReviseDate) VALUES ("
mySQL += "'" & UserN & "', '" & FileNo1 & "', " & FileNo2 & ", " & FileNo3 & ", '" & ST & "', '" & ET & "', " & CInt(studytime.Text) & ", "
mySQL += "0,'1900-01-01','N','" & Session("LoginNo") & "', GetDate() ,'" & Session("LoginNo") & "', GetDate())"
myCmd = New SqlCommand(mySQL, myCnn)
myCmd.ExecuteNonQuery()
End Using
If MailToUser.Checked = True Then
Call SendEmail_ClassList_Add("新增课程", UserN, FileNo1, FileNo2, FileNo3, Memo.Text)
End If
ST = ET : ET = ""
End If
Next
strMsg = "档案新增成功!"
Catch ex As Exception
'Response.Write("<b>●●● 请洽程式管理员●●●<br />程式错误讯息如下</b><br />" + ex.ToString() + "<HR />")
Dim strErr As String = "●●● 程式错误讯息如下 ●●●" & "\n\n" & Replace(Replace(Replace(Replace(Trim(ex.ToString()), Chr(10), ""), Chr(13), ""), "\", "\\"), "'", "\'")
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "alert", "alert('" & strErr & "');", True)
End Try
If strMsg <> "" Then
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "NotifyMsg", "alert('" & strMsg & "');", True)
Call RestData()
End If
End Sub
Protected Sub starttime_TextChanged(sender As Object, e As EventArgs) Handles starttime.TextChanged
Dim TempTime() As String = Split(starttime.Text, "-")
Dim Current_dt As DateTime = New DateTime(CInt(TempTime(0)), CInt(TempTime(1)), CInt(TempTime(2)))
endtime.Text = (DTAdd(Current_dt, ((ClassNo.Items.Count - 1) * 2)).ToShortDateString())
End Sub
Private Function DTAdd(dt As DateTime, addday As Integer) As DateTime
Dim i As Integer = 1
While (i <= addday)
dt = dt.AddDays(1)
If ((dt.DayOfWeek.ToString() <> "Saturday") And (dt.DayOfWeek.ToString() <> "Sunday")) Then
i += 1
End If
End While
Return dt
End Function