The Codes...,VB .Net & Sql -  ExchangForm.vb.
 
 
 

       
  Return


ExchangForm.vb


 

 The Codes ...
      ExchangForm.vb
 
 
Public Class ExchangForm

Inherits System.Windows.Forms.Form

Dim mbAddNewFlag As Boolean = False

Dim Date_flag As Boolean = False

 
Windows Form Designer generated code

Private Sub ExchangForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Try

'Attempt to load the dataset.

Me.LoadDataSet()

Catch eLoad As System.Exception

'Add your error handling code here.

'Display error message, if any.

System.Windows.Forms.MessageBox.Show(eLoad.Message)

End Try

Me.ExchangDSet_PositionChanged()

Me.txttdate.Text = System.DateTime.Now.ToLongDateString

' ToolTip

Me.ToolTip1.SetToolTip(Me.btnNavFirst, "First")

Me.ToolTip1.SetToolTip(Me.btnNavPrev, "Previous")

Me.ToolTip1.SetToolTip(Me.btnNavNext, "Next")

Me.ToolTip1.SetToolTip(Me.btnLast, "Last")

Me.ToolTip1.SetToolTip(Me.btnAdd, "New")

Me.ToolTip1.SetToolTip(Me.btnUpdate, "Update")

Me.ToolTip1.SetToolTip(Me.btnclose, "Close")

End Sub

Public Sub LoadDataSet()

'Create a new dataset to hold the records returned from the call to FillDataSet.

'A temporary dataset is used because filling the existing dataset would

'require the databindings to be rebound.

Dim objDataSetTemp As RBT_Accounting_Net.ExchangDSet

objDataSetTemp = New RBT_Accounting_Net.ExchangDSet

Try

'Attempt to fill the temporary dataset.

Me.FillDataSet(objDataSetTemp)

Catch eFillDataSet As System.Exception

'Add your error handling code here.

Throw eFillDataSet

End Try

Try

'Empty the old records from the dataset.

ExchangDSet1.Clear()

'Merge the records into the main dataset.

ExchangDSet1.Merge(objDataSetTemp)

Catch eLoadMerge As System.Exception

'Add your error handling code here.

Throw eLoadMerge

End Try

End Sub

Public Sub FillDataSet(ByVal dataSet As RBT_Accounting_Net.ExchangDSet)

'Turn off constraint checking before the dataset is filled.

'This allows the adapters to fill the dataset without concern

'for dependencies between the tables.

dataSet.EnforceConstraints = False

Try

'Open the connection.

Me.SqlConnection1.Open()

'Attempt to fill the dataset through the OleDbDataAdapter1.

Me.SqlDataAdapter1.Fill(dataSet)

Catch fillException As System.Exception

'Add your error handling code here.

Throw fillException

Finally

'Turn constraint checking back on.

dataSet.EnforceConstraints = True

'Close the connection whether or not the exception was thrown.

Me.SqlConnection1.Close()

End Try

End Sub

Private Sub ExchangDSet_PositionChanged()

Me.lblNavLocation.Text = (((Me.BindingContext(ExchangDSet1, "chang").Position + 1).ToString + " of ") _

+ Me.BindingContext(ExchangDSet1, "chang").Count.ToString)

If mbAddNewFlag = False Then

Me.DT_date.Visible = False

Me.editch_date.Visible = True

Me.editch_date.Left = 288

Me.editch_date.Top = 8

Me.Txteur.Text = Format(Val(editrate_eur.Text) * Val(Me.editllrate_usd.Text), "0.00")

Me.Txtuk.Text = Format(Val(Me.editrate_eng.Text) * Val(Me.editllrate_usd.Text), "0.00")

Me.Txtjap.Text = Format(Val(Me.editrate_jap.Text) * Val(Me.editllrate_usd.Text), "0.00")

End If

' Navigation controls enebled(True or False

If Me.BindingContext(ExchangDSet1, "chang").Position + 1 = 1 Then

NavigationFP(False)

NavigationNL(True)

ElseIf Me.BindingContext(ExchangDSet1, "chang").Position + 1 = Me.BindingContext(ExchangDSet1, "chang").Count Then

NavigationFP(True)

NavigationNL(False)

Else

NavigationFP(True)

NavigationNL(True)

End If

Me.lblNavLocation.Focus()

End Sub

Private Sub NavigationFP(ByVal bval As Boolean)

Me.btnNavFirst.Enabled = bval

Me.btnNavPrev.Enabled = bval

End Sub

Private Sub NavigationNL(ByVal bval As Boolean)

Me.btnNavNext.Enabled = bval

Me.btnLast.Enabled = bval

End Sub

' Navigation

Private Sub btnNavFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNavFirst.Click

Me.BindingContext(ExchangDSet1, "chang").Position = 0

Me.ExchangDSet_PositionChanged()

End Sub

' Navigation

Private Sub btnNavPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNavPrev.Click

Me.BindingContext(ExchangDSet1, "chang").Position = (Me.BindingContext(ExchangDSet1, "chang").Position - 1)

Me.ExchangDSet_PositionChanged()

End Sub

' Navigation

Private Sub btnNavNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNavNext.Click

Me.BindingContext(ExchangDSet1, "chang").Position = (Me.BindingContext(ExchangDSet1, "chang").Position + 1)

Me.ExchangDSet_PositionChanged()

End Sub

' Navigation

Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click

Me.BindingContext(ExchangDSet1, "chang").Position = (Me.ExchangDSet1.Tables("chang").Rows.Count - 1)

Me.ExchangDSet_PositionChanged()

End Sub

' Add new record

Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

Date_flag = True

Try

'Clear out the current edits

Me.BindingContext(ExchangDSet1, "chang").EndCurrentEdit()

Me.BindingContext(ExchangDSet1, "chang").AddNew()

Me.editch_date.Visible = False

DT_date.Visible = True

Me.DT_date.Text = System.DateTime.Now.ToShortDateString

Me.editch_date.Text = System.DateTime.Now.ToShortDateString

mbAddNewFlag = True

SetButtons(False)

Panel1.Enabled = True

lnote1.Visible = True

Me.Txtusd.Text = "1.00"

Me.Txteur.Text = " "

Me.Txtuk.Text = " "

Me.Txtjap.Text = " "

Me.editllrate_usd.Focus()

Catch eEndEdit As System.Exception

System.Windows.Forms.MessageBox.Show(eEndEdit.Message)

End Try

Me.ExchangDSet_PositionChanged()

End Sub

Private Sub SetButtons(ByVal bVal As Boolean)

Me.btnNavFirst.Enabled = bVal

Me.btnNavPrev.Enabled = bVal

Me.btnNavNext.Enabled = bVal

Me.btnLast.Enabled = bVal

Me.btnAdd.Enabled = bVal

Me.btnUpdate.Enabled = Not bVal

Me.btnclose.Enabled = bVal

End Sub

' Save the new record

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click

Try

Panel1.Enabled = False

SetButtons(True)

Me.btnUpdate.Enabled = False

mbAddNewFlag = False

Me.lnote1.Visible = False

'Attempt to update the datasource.

Me.UpdateDataSet()

Catch eUpdate As System.Exception

'Add your error handling code here.

'Display error message, if any.

System.Windows.Forms.MessageBox.Show(eUpdate.Message)

End Try

Me.ExchangDSet_PositionChanged()

Date_flag = False

editch_date_TextChanged(editch_date, e.Empty)

End Sub

Public Sub UpdateDataSet()

'Create a new dataset to hold the changes that have been made to the main dataset.

Dim objDataSetChanges As RBT_Accounting_Net.ExchangDSet = New RBT_Accounting_Net.ExchangDSet

'Stop any current edits.

Me.BindingContext(ExchangDSet1, "chang").EndCurrentEdit()

'Get the changes that have been made to the main dataset.

objDataSetChanges = CType(ExchangDSet1.GetChanges, RBT_Accounting_Net.ExchangDSet)

'Check to see if any changes have been made.

If (Not (objDataSetChanges) Is Nothing) Then

Try

'There are changes that need to be made, so attempt to update the datasource by

'calling the update method and passing the dataset and any parameters.

Me.UpdateDataSource(objDataSetChanges)

ExchangDSet1.Merge(objDataSetChanges)

ExchangDSet1.AcceptChanges()

Catch eUpdate As System.Exception

'Add your error handling code here.

Throw eUpdate

End Try

'Add your code to check the returned dataset for any errors that may have been

'pushed into the row object's error.

End If

End Sub

Public Sub UpdateDataSource(ByVal ChangedRows As RBT_Accounting_Net.ExchangDSet)

Try

'The data source only needs to be updated if there are changes pending.

If (Not (ChangedRows) Is Nothing) Then

'Open the connection.

Me.SqlConnection1.Open()

'Attempt to update the data source.

Me.SqlDataAdapter1.Update(ChangedRows)

End If

Catch updateException As System.Exception

'Add your error handling code here.

Throw updateException

Finally

'Close the connection whether or not the exception was thrown.

Me.SqlConnection1.Close()

End Try

End Sub

' Unload the current Form

Private Sub btnclose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclose.Click

Me.Close()

End Sub

Private Sub editllrate_usd_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles editllrate_usd.DoubleClick

Me.editrate_ll.Text = 1 / Val(editllrate_usd.Text)

editrate_eur.Focus()

End Sub

Private Sub editrate_eur_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles editrate_eur.DoubleClick

Me.Txteur.Text = Format(Val(Me.editrate_eur.Text) * Val(Me.editllrate_usd.Text), "0.00")

Me.editrate_eng.Focus()

End Sub

Private Sub editrate_eng_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles editrate_eng.DoubleClick

Me.Txtuk.Text = Format(Val(Me.editrate_eng.Text) * Val(Me.editllrate_usd.Text), "0.00")

Me.Txtjap.Focus()

End Sub

Private Sub editrate_jap_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles editrate_jap.DoubleClick

Me.Txtjap.Text = Format(Val(Me.editrate_jap.Text) * Val(Me.editllrate_usd.Text), "0.00")

Me.btnUpdate.Enabled = True

End Sub

 

Private Sub DT_date_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DT_date.ValueChanged

Dim eddate As Date

If mbAddNewFlag Then

Date_flag = True

eddate = Me.DT_date.Value

editch_date.Text = eddate.ToShortDateString

Me.editllrate_usd.Focus()

End If

End Sub

Private Sub editch_date_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles editch_date.TextChanged

Dim eddatex As DateTime

If Date_flag = False Then

eddatex = editch_date.Text

editch_date.Text = eddatex.ToShortDateString

End If

End Sub

End Class

 


 

  Return