Public Class frmDesignation1
    Private Sub SimpleButton1_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
        If txtDesignation.Text = "" Then
            ErrorProvider1.SetError(txtDesignation, "Mandatory field.")
        Else
            ErrorProvider1.Clear()
            ErrorProvider2.Clear()

            If btnSubmit.Text = "SAVE" Then
                ExecuteSQLQuery(" INSERT INTO Designation (DesignationName) VALUES ('" + str_repl(txtDesignation.Text) + "') ")
            ElseIf btnSubmit.Text = "UPDATE" Then
                ExecuteSQLQuery("UPDATE  Designation SET DesignationName='" + str_repl(txtDesignation.Text) + "' WHERE DESG_ID=" & num_fltr(txtDESG_ID.Text) & " ")
            End If
            LoadData()
            btnSubmit.Text = "SAVE"
            txtDESG_ID.Text = ""
            txtDesignation.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 DESG_ID, DesignationName FROM Designation", dataset1)
        GridControl1.DataSource = dataset1.DataSource
    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("DesignationName").ToString(), MsgBoxStyle.YesNo + MsgBoxStyle.Exclamation, "Confirm..") = MsgBoxResult.Yes Then
            ExecuteSQLQuery("DELETE FROM  Department  WHERE DESG_ID=" & num_fltr(GridView1.GetFocusedRowCellValue("DESG_ID").ToString()) & " ")
            LoadData()
            MsgBox("Data has been deleted successfully.", MsgBoxStyle.Information, "Information")
        End If
    End Sub

    Private Sub frmDesignation1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        LoadData()
    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("DesignationName").ToString(), MsgBoxStyle.YesNo + MsgBoxStyle.Exclamation, "Confirm..") = MsgBoxResult.Yes Then
            txtDESG_ID.Text = GridView1.GetFocusedRowCellValue("DESG_ID").ToString()
            txtDesignation.Text = GridView1.GetFocusedRowCellValue("DesignationName").ToString()
            btnSubmit.Text = "UPDATE"

        End If
    End Sub
End Class