Partial Class AddPettyCash_H
Inherits System.Web.UI.Page
Dim clsDB As New clsDatabase
Dim FYear As Long
Dim FMonth As Integer
Dim FDay As Integer
Dim DMYS As Date
Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList2.SelectedIndexChanged
FMonth = Int32.Parse(DropDownList2.SelectedValue)
FYear = Int32.Parse(DropDownList3.SelectedValue)
DMYS = FYear & "/" & FMonth & "/" & 1
DMYS = DateAdd("d", -1, DateAdd("m", 1, DMYS))
FDay = Day(DMYS)
End Sub
Protected Sub DropDownList3_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList3.SelectedIndexChanged
FMonth = Int32.Parse(DropDownList2.SelectedValue)
FYear = Int32.Parse(DropDownList3.SelectedValue)
DMYS = FYear & "/" & FMonth & "/" & 1
DMYS = DateAdd("d", -1, DateAdd("m", 1, DMYS))
FDay = Day(DMYS)
End Sub
Function CheckLeap(ByVal fyear As Long) As Boolean
If (fyear Mod 4 = 0) Then
CheckLeap = True
Else
CheckLeap = False
End If
End Function
Function CheckDate(ByVal fday As Integer, ByVal fmonth As Integer, ByVal fyear As Integer) As Boolean
If IsDate(fday & "/" & fmonth & "/" & fyear) Then
CheckDate = True
Else
CheckDate = False
End If
End Function
Protected Sub Page_InitComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.InitComplete
If Session("strUser") = Nothing Then
Response.Redirect("index.aspx")
Exit Sub
End If
Label2.Text = Session("strUser")
LblUserGroup.Text = Session("UserGroup")
LblBr_id.Text = Session("BR_ID")
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim tnow As Date
tnow = DateTime.Now
Dim AlYear() As Integer
Dim AlMonth(11) As Integer
Dim NumYear As Integer
NumYear = Year(Now) - 2002
Dim i As Integer
ReDim AlYear(NumYear)
For i = 2002 To Year(Now)
AlYear(NumYear) = i
NumYear = NumYear - 1
Next i
For i = 1 To 12
AlMonth(i - 1) = i
Next i
If Page.IsPostBack Then
FYear = Int32.Parse(DropDownList3.SelectedValue)
FMonth = Int32.Parse(DropDownList2.SelectedValue)
DropDownList3.DataSource = AlYear
DropDownList3.DataBind()
DropDownList3.SelectedValue = FYear
DropDownList2.DataSource = AlMonth
DropDownList2.DataBind()
DropDownList2.SelectedValue = FMonth
DMYS = FYear & "/" & FMonth & "/" & 1
DMYS = DateAdd("d", -1, DateAdd("m", 1, DMYS))
Label1.Text = DMYS
Else
DropDownList3.DataSource = AlYear
DropDownList3.DataBind()
DropDownList3.SelectedValue = tnow.Year.ToString()
DropDownList2.DataSource = AlMonth
DropDownList2.DataBind()
DropDownList2.SelectedValue = tnow.Month.ToString()
FYear = Int32.Parse(DropDownList3.SelectedValue)
FMonth = Int32.Parse(DropDownList2.SelectedValue)
DMYS = FYear & "/" & FMonth & "/" & 1
DMYS = DateAdd("d", -1, DateAdd("m", 1, DMYS))
Label1.Text = DMYS
End If
Label2.Text = Session("strUser")
TxtTopic.Focus()
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'Insert To H
Dim dbread As OleDbDataReader
Dim rcount As Integer
Dim num As Long
Label1.Text = Year(Label1.Text) & "/" & Month(Label1.Text) & "/" & Day(Label1.Text)
Dim strSQL As String
strSQL = "SELECT TOP 1 ExpensNo FROM PETTYCASH_H ORDER BY ExpensNo DESC"
dbread = clsDB.QueryDataReader(strSQL)
rcount = dbread.Read()
If rcount <> 0 Then
num = dbread("ExpensNo")
Else
num = 0
End If
clsDB.Close()
Dim dDate As Date
strSQL = "INSERT INTO PETTYCASH_H(ExpensNo,Month_Date,DESCP,Account,USER_NAME,FlagUpdate,FlagCancel)" & _
" VALUES(" & num + 1 & ",#" & Month(Label1.Text) & "/" & Day(Label1.Text) & "/" & Year(Label1.Text) & "#,'" & TxtTopic.Text & "','" & TxtAccID.Text & "','" & Label2.Text & "',0,0)"
If clsDB.QueryExecuteNonQuery(strSQL) = True Then
dDate = Year(Label1.Text) & "/" & Month(Label1.Text) & "/" & Day(Label1.Text)
Session("ExpensNo") = num + 1
Response.Redirect("ADDPETTYCASH_D.aspx")
Else
LblError.Visible = True
LblError.Text = "Insert Not Complate!"
End If
clsDB.Close()
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
TxtTopic.Text = ""
TxtAccID.Text = ""
TxtTopic.Focus()
End Sub
End Class
Public Class clsDatabase
Inherits System.Web.UI.Page
Private objConn As OleDbConnection
Private objCmd As OleDbCommand
Private Trans As OleDbTransaction
Private strConnString As String
Public Sub New()
'strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("App_data/dbPettyCash.mdb") & ";Jet OLEDB:Database Password=;"
strConnString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString").ToString
End Sub
Public Function ConnOnly(ByVal xx As String) As DataTable
Dim dt As New DataTable
objConn = New OleDbConnection
With objConn
.ConnectionString = strConnString
.Open()
End With
dt = objConn.GetSchema(xx)
Return dt
End Function
Public Function QueryDataReader(ByVal strSQL As String) As OleDbDataReader
Dim dtReader As OleDbDataReader
objConn = New OleDbConnection
With objConn
.ConnectionString = strConnString
.Open()
End With
objCmd = New OleDbCommand(strSQL, objConn)
dtReader = objCmd.ExecuteReader()
Return dtReader '*** Return DataReader ***'
End Function
Public Function QueryDataSet(ByVal strSQL As String) As DataSet
Dim ds As New DataSet
Dim dtAdapter As New OleDbDataAdapter
objConn = New OleDbConnection
With objConn
.ConnectionString = strConnString
.Open()
End With
objCmd = New OleDbCommand
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
dtAdapter.SelectCommand = objCmd
dtAdapter.Fill(ds)
Return ds '*** Return DataSet ***'
End Function
Public Function QueryDataTable(ByVal strSQL As String) As DataTable
Dim dtAdapter As OleDbDataAdapter
Dim dt As New DataTable
objConn = New OleDbConnection
With objConn
.ConnectionString = strConnString
.Open()
End With
dtAdapter = New OleDbDataAdapter(strSQL, objConn)
dtAdapter.Fill(dt)
Return dt '*** Return DataTable ***'
End Function
Public Function QueryExecuteNonQuery(ByVal strSQL As String) As Boolean
objConn = New OleDbConnection
With objConn
.ConnectionString = strConnString
.Open()
End With
Try
objCmd = New OleDbCommand()
With objCmd
.Connection = objConn
.CommandType = CommandType.Text
.CommandText = strSQL
End With
objCmd.ExecuteNonQuery()
Return True '*** Return True ***'
Catch ex As Exception
MsgBox(ex.Message)
Return False '*** Return False ***'
End Try
End Function
Public Function QueryExecuteScalar(ByVal strSQL As String) As Object
Dim obj As Object
objConn = New OleDbConnection
With objConn
.ConnectionString = strConnString
.Open()
End With
Try
objCmd = New OleDbCommand()
With objCmd
.Connection = objConn
.CommandType = CommandType.Text
.CommandText = strSQL
End With
obj = objCmd.ExecuteScalar() '*** Return Scalar ***'
Return obj
Catch ex As Exception
Return Nothing '*** Return Nothing ***'
End Try
End Function
Public Sub Close()
objConn.Close()
objConn = Nothing
End Sub
End Class