I have problem with saving entry to mysql.. first entry saved but it doesnt work with second, somehow the save_new button didnt respond at all.. then i use saveandclose button it works or after i restart the pc the save_new button function will do it job for the first entry i add after that ..
save_new will call frmcuti_onSave function
saveandclose will call frmcuti_onSaveClose function
this the frmcuti.vb
#Region "Imports"
Imports System.Data.SqlClient
#End Region
Public Class frmcuti
Private m_Cuti As New Entity_Penggajian.Cuti
Private m_GetHari As New GlobalValidasi
Private m_CutiA As New BussinessComponents.Cuti
Private m_DS As New DataSet
Private m_dta As SqlDataAdapter
Private datagrid As DataView
Private check As Boolean = True
Private Sub frmcuti_onLoaded(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.onLoaded
MyBase.Form = FormType.Cuti
Call UscIDTextBox1.Initialize("IC")
End Sub
Private Sub save(ByRef e)
Try
With m_Cuti
.ID_Cuti = UscIDTextBox1.TextBox1.Text
.Nik = TextBox2.Text
.Tanggal_awal = DateTimePicker1.Value.Date
.Tanggal_akhir = DateTimePicker2.Value.Date
.Status = ComboBox1.GetItemText(ComboBox1.SelectedItem)
.Lama_Cuti = IIf(.Status = "Izin", 0, CType(TextBox5.Text, Integer))
If .Status = "Cuti Hamil" Then
.Sisa_hari = CType(TextBox4.Text, Integer)
Else
.Sisa_hari = CType(TextBox4.Text, Integer) - .Lama_Cuti
End If
.Descripsi = TextBox3.Text
.ID = "IC"
With New BussinessComponents.Cuti
.Add(m_Cuti)
End With
End With
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub SetInitdata()
UscIDTextBox1.Initialize("IC")
TextBox2.Text = ""
ComboBox1.SelectedValue = ""
DateTimePicker2.Value = Date.Now
DateTimePicker1.Value = Date.Now
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
End Sub
Private Sub frmcuti_onSave(ByVal sender As Object, ByVal e As FormBase.SaveEventArgs) Handles Me.onSave
Call save(e)
Call SetInitdata()
End Sub
.
.
.
Private Sub frmcuti_onSaveClose(ByVal sender As Object, ByVal e As FormBase.SaveEventArgs) Handles Me.onSaveClose
Call save(e)
Me.Dispose()
End Sub
Private Sub frmcuti_onValidator(ByVal sender As Object, ByVal e As FormBase.SaveEventArgs) Handles Me.onValidator
If Not MyBase.RequiredFieldValidator(UscIDTextBox1.TextBox1, Label3.Text, e) Then
If Not MyBase.RequiredFieldValidator(TextBox2, Label2.Text, e) Then
If Not MyBase.RequiredFieldValidator(ComboBox1, Label6.Text, e) Then
If Not MyBase.RequiredFieldValidator(TextBox4, Label7.Text, e) Then
If ComboBox1.SelectedIndex = 1 Then
If TextBox4.Text <> 90 Then
e.error = True
e.message = "Lama Hari Harus 90"
End If
Else
If ComboBox1.SelectedIndex = 0 Then
If CType(TextBox5.Text, Integer) > CType(TextBox4.Text, Integer) Then
e.error = True
e.message = "Hari tidak boleh lebih dari sisa cuti"
End If
Else
If TextBox5.Text > 3 Then
e.error = True
e.message = "Izin tidak boleh lebih dari 3 hari "
End If
End If
End If
With New BussinessComponents.Cuti
If .Validate(UscIDTextBox1.TextBox1.Text, DateTimePicker1.Value, DateTimePicker2.Value) Then
e.error = True
e.message = "Tanggal Sudah pernah digunakan untuk ijin"
Else
If Month(DateTimePicker1.Value) <> Month(DateTimePicker2.Value) Then
e.error = True
e.message = "Tanggal cuti yang diambil Harus dalam Satu Bulan"
End If
End If
End With
End If
End If
End If
End If
End Sub
End Class
and this the BussinessComponents.Cuti code
Public Class Cuti : Inherits ComponentBase
Public Sub Add(ByVal oData As Entity_Penggajian.Cuti)
Dim oParam(7) As SqlParameter
With oData
oParam(0) = New SqlParameter("@ID_Izin", SqlDbType.VarChar)
oParam(0).Value = .ID_Cuti
oParam(1) = New SqlParameter("@Tgl_akhir", SqlDbType.DateTime)
oParam(1).Value = .Tanggal_akhir
oParam(2) = New SqlParameter("@Tgl_awal", SqlDbType.DateTime)
oParam(2).Value = .Tanggal_awal
oParam(3) = New SqlParameter("@Status", SqlDbType.VarChar)
oParam(3).Value = .Status
oParam(4) = New SqlParameter("@Sisa", SqlDbType.Int)
oParam(4).Value = .Sisa_hari
oParam(5) = New SqlParameter("@Descripsi", SqlDbType.VarChar)
If .Descripsi Is Nothing Then
oParam(5).Value = DBNull.Value
Else
oParam(5).Value = .Descripsi
End If
oParam(6) = New SqlParameter("@Nik", SqlDbType.VarChar)
oParam(6).Value = .Nik
oParam(7) = New SqlParameter("@ID", SqlDbType.VarChar)
oParam(7).Value = .ID
Try
SqlHelper.ExecuteNonQuery(oConnectionString, CommandType.StoredProcedure, "spIzin", oParam)
Catch ex As Exception
MsgBox(ex.Message)
Throw ex
End Try
End With
End Sub
Public Function DataCutiAdapter() As SqlDataAdapter
Dim oAdapter As New SqlDataAdapter
Dim oCommand As New SqlCommand
Dim cmb As SqlCommandBuilder
oCommand.CommandText = "spCuti"
oCommand.CommandType = CommandType.StoredProcedure
oCommand.Connection = MyBase.oConnectionString
oAdapter.SelectCommand = oCommand
cmb = New SqlCommandBuilder(oAdapter)
Return oAdapter
End Function
Public Function GetSisaHari(ByVal nik As String) As Integer
Dim oParam As SqlParameter
Dim dtr As SqlDataReader
oParam = New SqlParameter("@Nik", SqlDbType.VarChar)
oParam.Value = nik
Try
dtr = SqlHelper.ExecuteReader(oConnectionString, CommandType.StoredProcedure, "spSisaHari", oParam)
Catch ex As Exception
Throw ex
MsgBox(ex.Message)
End Try
If dtr.HasRows Then
dtr.Read()
Return dtr.Item(0)
Else
Return 12
End If
End Function
Public Function GajiPokok(ByVal bulan As String, ByVal tahun As Integer) As Double
Dim oParam(1) As SqlParameter
Dim dtrdata As SqlDataReader
oParam(0) = New SqlParameter("@Bulan", SqlDbType.VarChar)
oParam(0).Value = bulan
oParam(1) = New SqlParameter("@Tahun", SqlDbType.Int)
oParam(1).Value = tahun
Try
dtrdata = SqlHelper.ExecuteReader(oConnectionString3, CommandType.StoredProcedure, "spHariKerja", oParam)
If dtrdata.HasRows Then
dtrdata.Read()
Return dtrdata.Item(0)
End If
Catch ex As SqlException
MsgBox(ex.Message)
End Try
End Function
Public Function Validate(ByVal nik As String, ByVal oDate1 As Date, ByVal oDate2 As Date) As Boolean
Dim oParams(2) As SqlParameter
dim dtr as SqlDataReader
oParams(0) = New SqlParameter("@Nik", SqlDbType.VarChar)
oParams(0).Value = nik
oParams(1) = New SqlParameter("@Date1", SqlDbType.VarChar)
oParams(1).Value = oDate1
oParams(2) = New SqlParameter("@Date2", SqlDbType.VarChar)
oParams(2).Value = oDate2
Try
dtr = SqlHelper.ExecuteReader(oConnectionString, CommandType.StoredProcedure, "spValidate", oParams)
If dtr.HasRows Then
Return True
Else
Return False
End If
Catch ex As Exception
End Try
End Function
End Class