Public Class Form1
Private Enum Actions
Create
Retrieve
Update
Delete
OpenNew
Validate
Save
End Enum
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "Resource Entity example"
'Assign controls label
Button1.Text = "Create" : Button2.Text = "Retrieve"
Button3.Text = "Update" : Button4.Text = "Delete"
Button5.Text = "OpenNew" : Button6.Text = "Validate"
Button7.Text = "Save"
Label1.Text = "Resource ID" : Label2.Text = "Last Name"
Label3.Text = "User ID" : Label4.Text = "Full Name"
Label5.Text = "Employment Start Date"
Label6.Text = "Server" : Label7.Text = "Database"
Label8.Text = URL:Port
Label9.Text = "http://<server>:Port/Services"
' Enter default URL, Server and Database settings here.
TextBox8.Text = "http://change_me:8010/services"
TextBox6.Text = "change_me"
TextBox7.Text = "001"
End Sub
''' <summary>
''' Create record action
''' </summary>
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
DoAction(Actions.Create)
End Sub
''' <summary>
''' Retrieve record action
''' </summary>
Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
DoAction(Actions.Retrieve)
End Sub
''' <summary>
''' Update record action
''' </summary>
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
DoAction(Actions.Update)
End Sub
''' <summary>
''' Delete record action
''' </summary>
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
DoAction(Actions.Delete)
End Sub
''' <summary>
''' Open new record action
''' </summary>
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
DoAction(Actions.OpenNew)
End Sub
''' <summary>
''' Validate record action
''' </summary>
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
DoAction(Actions.Validate)
End Sub
''' <summary>
''' Save record action
''' </summary>
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
DoAction(Actions.Save)
End Sub
''' <summary>
''' Helper function to assign Text fields value to EntityData
''' </summary>
Private Function GetFormData() As Exact.Services.Client.Data.EntityData
Dim Data As New Exact.Services.Client.Data.EntityData
Data.EntityName = "Resource"
If Not String.IsNullOrWhiteSpace(TextBox1.Text) Then
Data.Properties.Add(New Exact.Services.Client.Data.PropertyData _
With {.Name = "ID", .Value = TextBox1.Text})
End If
Data.Properties.Add(New Exact.Services.Client.Data.PropertyData _
With {.Name = "LastName", .Value = TextBox2.Text})
Data.Properties.Add(New Exact.Services.Client.Data.PropertyData _
With {.Name = "UserID", .Value = TextBox3.Text})
Data.Properties.Add(New Exact.Services.Client.Data.PropertyData _
With {.Name = "FullName", .Value = TextBox4.Text})
If Not String.IsNullOrWhiteSpace(TextBox5.Text) Then
Data.Properties.Add(New Exact.Services.Client.Data.PropertyData _
With {.Name = "EmploymentStartDate", .Value = TextBox5.Text})
End If
Return Data
End Function
''' <summary>
''' Helper function to assign EntityData to Text fields
''' </summary>
Private Sub FillData(ByVal Data As Exact.Services.Client.Data.EntityData)
TextBox1.Text = Data.Properties("ID").Value
TextBox2.Text = Data.Properties("LastName").Value
TextBox3.Text = Data.Properties("UserID").Value
TextBox4.Text = Data.Properties("FullName").Value
TextBox5.Text = Data.Properties("EmploymentStartDate").Value
End Sub
''' <summary>
''' To perform CRUDOVS action using entityClient object
''' 1. Crate entityClient object
''' 2. Assigning all user input into EntityData by calling the function GetFormData()
''' 3. Pass EntityData object (from GetFormData()) to the entityClient CRUDOVS methods.
''' 4. Fill returned data from entityClient CRUDOVS methods by FillData() method.(Only if CRUDOVS methods is not a Sub method.
''' </summary>
Private Sub DoAction(action As Actions)
Try
Dim entityClient As New Exact.Services.Client.Entity.EntityClientEG(TextBox8.Text, TextBox6.Text, TextBox7.Text)
Select Case action
Case Actions.Create : FillData(entityClient.Create(GetFormData()))
Case Actions.Delete : entityClient.Delete(GetFormData())
Case Actions.OpenNew : FillData(entityClient.OpenNew(GetFormData()))
Case Actions.Retrieve : FillData(entityClient.Retrieve(GetFormData()))
Case Actions.Save : FillData(entityClient.Save(GetFormData()))
Case Actions.Update : entityClient.Update(GetFormData())
Case Actions.Validate : FillData(entityClient.Validate(GetFormData()))
End Select
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
End Class
|