Public Class frmDepartment1
    Private Sub TextEdit1_EditValueChanged(sender As Object, e As EventArgs) Handles txtDepartment.EditValueChanged

    End Sub

    Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
        If txtDepartment.Text = "" Then
            ErrorProvider1.SetError(txtDepartment, "Department Name.")
        Else
            ErrorProvider1.Clear()
            If btnSubmit.Text = "SAVE" Then
                ExecuteSQLQuery("INSERT INTO Department (DepartmentName, DepartmentHead) VALUES ('" + str_repl(txtDepartment.Text) + "' , '" + str_repl(txtDepartmenthead.Text) + "')")
            ElseIf btnSubmit.Text = "UPDATE" Then
                ExecuteSQLQuery("UPDATE  Department SET DepartmentName='" + str_repl(txtDepartment.Text) + "',  DepartmentHead='" + str_repl(txtDepartmenthead.Text) + "' WHERE DEP_ID=" & num_fltr(txtDepID.Text) & " ")
            End If
            LoadData()
            btnSubmit.Text = "SAVE"
            txtDepID.Text = ""
            txtDepartment.Text = ""
            MsgBox("Information has been saved successfully.", MsgBoxStyle.Information, "Information")
        End If
    End Sub

    Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub
    Private Sub LoadData()
        Dim dataset1 As New DataGridView
        FillDataGrid("SELECT DEP_ID, DepartmentName, DepartmentHead FROM Department", dataset1)
        FillDataComboBobox11("SELECT * FROM applicationuser", "USER_ID", "User_Name", txtDepartmenthead)
        GridControl1.DataSource = dataset1.DataSource
    End Sub

    Private Sub Edit1_ButtonClick(sender As Object, e As DevExpress.XtraEditors.Controls.ButtonPressedEventArgs) Handles Edit1.ButtonClick
        If MsgBox("Are you sure to edit: " & GridView1.GetFocusedRowCellValue("DepartmentName").ToString(), MsgBoxStyle.YesNo + MsgBoxStyle.Exclamation, "Confirm..") = MsgBoxResult.Yes Then
            txtDepID.Text = GridView1.GetFocusedRowCellValue("DEP_ID").ToString()
            txtDepartment.Text = GridView1.GetFocusedRowCellValue("DepartmentName").ToString()
            txtDepartmenthead.Text = GridView1.GetFocusedRowCellValue("DepartmentHead").ToString()
            btnSubmit.Text = "UPDATE"
        End If
    End Sub

    Private Sub delete1_ButtonClick(sender As Object, e As DevExpress.XtraEditors.Controls.ButtonPressedEventArgs) Handles delete1.ButtonClick
        If MsgBox("Are you sure to delete: " & GridView1.GetFocusedRowCellValue("DepartmentName").ToString(), MsgBoxStyle.YesNo + MsgBoxStyle.Exclamation, "Confirm..") = MsgBoxResult.Yes Then
            ExecuteSQLQuery("DELETE FROM  Department  WHERE DEP_ID=" & num_fltr(GridView1.GetFocusedRowCellValue("DEP_ID").ToString()) & " ")
            LoadData()
            MsgBox("Data has been deleted successfully.", MsgBoxStyle.Information, "Information")
        End If
    End Sub

    Private Sub frmDepartment1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        LoadData()
    End Sub


End Class