#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_onEdit(ByVal sender As Object, ByVal e As FormBase.SaveEventArgs) Handles Me.onEdit
Call Edit()
End Sub
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
Public Sub Edit()
DataGridView1.AllowUserToAddRows = False
m_dta = New SqlDataAdapter
m_DS.Clear()
m_dta = m_CutiA.DataCutiAdapter
m_dta.Fill(m_DS)
DataGrid = m_DS.Tables(0).DefaultView
DataGridView1.DataSource = DataGrid
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
Public Sub search()
DataGrid = m_DS.Tables(0).DefaultView
datagrid.RowFilter = "ID_Cuti like'" & MyBase.getID & "%'"
DataGridView1.DataSource = DataGrid
End Sub
Public Sub Updated()
DataGridView1.EndEdit()
m_dta.Update(m_DS.Tables(0))
DataGridView1.DataSource = Nothing
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 DateTimePicker1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles DateTimePicker1.Enter
DateTimePicker1.MaxDate = DateTimePicker2.Value
End Sub
Private Sub DateTimePicker2_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles DateTimePicker2.Enter
DateTimePicker2.MinDate = DateTimePicker1.Value
End Sub
Private Sub DateTimePicker1_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
If DateTimePicker1.Value <= DateTimePicker2.Value Then
TextBox5.Text = m_GetHari.GetHari(DateTimePicker1.Value.Date, DateTimePicker2.Value.Date)
Else
DateTimePicker1.Value = Date.Now
MsgBox("Tanggal_awal tidak boleh melebihi Tanggal Akhir", MsgBoxStyle.Exclamation)
End If
End Sub
Private Sub DateTimePicker2_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DateTimePicker2.ValueChanged
If DateTimePicker1.Value <= DateTimePicker2.Value Then
TextBox5.Text = m_GetHari.GetHari(DateTimePicker1.Value.Date, DateTimePicker2.Value.Date)
Else
DateTimePicker2.Value = Date.Now
MsgBox("Tanggal_awal tidak boleh melebihi Tanggal Akhir", MsgBoxStyle.Exclamation)
End If
If ComboBox1.SelectedIndex = 2 Then
If CType(TextBox5.Text, Integer) > 3 Then
DateTimePicker2.Value = Date.Now
TextBox5.Text = 0
check = True
MsgBox("Ijin maksimal 3 hari", MsgBoxStyle.Exclamation)
End If
End If
If check Then
If CType(TextBox5.Text, Integer) > CType(TextBox4.Text, Integer) Then
DateTimePicker2.Value = Date.Now
TextBox5.Text = 0
MsgBox("Lewat sisa hari", MsgBoxStyle.Exclamation)
End If
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
frmkaryawanSearch.Show()
frmkaryawanSearch.FormAction = frmkaryawanSearch.FormAdd.Cuti
frmkaryawanSearch.MdiParent = MDIParent1
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
With New BussinessComponents.Cuti
TextBox4.Text = .GetSisaHari(TextBox2.Text)
End With
End Sub
Private Sub ComboBox1_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedValueChanged
If ComboBox1.SelectedIndex = 1 Then
check = False
DateTimePicker2.Value = DateTimePicker1.Value.AddDays(90)
ElseIf ComboBox1.SelectedIndex = 2 Then
If CType(TextBox5.Text, Integer) > 3 Then
DateTimePicker2.Value = Date.Now
TextBox5.Text = 0
check = True
MsgBox("Ijin maksimal 3 hari", MsgBoxStyle.Exclamation)
End If
Else
check = True
End If
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_onUpdate(ByVal sender As Object, ByVal e As FormBase.SaveEventArgs) Handles Me.onUpdate
Call Updated()
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
hi everyone i have a bit problem here.. after successfully save first entry with save_new button, i cannot save different entry again with save_new button, but it works if i use save and close button..any idea?