Account_Form.vb |
Public
Class
Account_Form
Inherits System.Windows.Forms.Form
Windows Form Designer generated code |
Private
Sub
Account_Form_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.Account_DSet_PositionChanged()
' Date, today
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.Account_DSet
objDataSetTemp =
New RBT_Accounting_Net.Account_DSet
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.
Account_DSet1.Clear()
'Merge the
records into the main dataset.
Account_DSet1.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.Account_DSet)
'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 SqlDataAdapter1.
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
Account_DSet_PositionChanged()
Me.lblNavLocation.Text
= (((Me.BindingContext(Account_DSet1,
"cust_comp").Position + 1).ToString + " of ") _
+ Me.BindingContext(Account_DSet1,
"cust_comp").Count.ToString)
' Navigation
controls enebled(True or False
If
Me.BindingContext(Account_DSet1,
"cust_comp").Position + 1 = 1
Then
NavigationFP( False)
NavigationNL( True)
ElseIf
Me.BindingContext(Account_DSet1,
"cust_comp").Position + 1 =
Me.BindingContext(Account_DSet1,
"cust_comp").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(Account_DSet1,
"cust_comp").Position = 0
Me.Account_DSet_PositionChanged()
End
Sub
' Navigation
Private
Sub
btnNavPrev_Click(ByVal
sender As
System.Object, ByVal
e As
System.EventArgs)
Handles btnNavPrev.Click
Me.BindingContext(Account_DSet1,
"cust_comp").Position = (Me.BindingContext(Account_DSet1,
"cust_comp").Position - 1)
Me.Account_DSet_PositionChanged()
End
Sub
' Navigation
Private
Sub
btnNavNext_Click(ByVal
sender As
System.Object, ByVal
e As
System.EventArgs)
Handles btnNavNext.Click
Me.BindingContext(Account_DSet1,
"cust_comp").Position = (Me.BindingContext(Account_DSet1,
"cust_comp").Position + 1)
Me.Account_DSet_PositionChanged()
End
Sub
' Navigation
Private
Sub
btnLast_Click(ByVal
sender As
System.Object, ByVal
e As
System.EventArgs)
Handles btnLast.Click
Me.BindingContext(Account_DSet1,
"cust_comp").Position = (Me.Account_DSet1.Tables("cust_comp").Rows.Count
- 1)
Me.Account_DSet_PositionChanged()
End
Sub
' Add New recod
Private
Sub
btnAdd_Click(ByVal
sender As
System.Object, ByVal
e As
System.EventArgs)
Handles btnAdd.Click
Dim
ThisValue As
String
' cust_comp
Table, SqlCommand & SqlDataAdapter & DataSet controls
Dim
selectCMD As
System.Data.SqlClient.SqlCommand =
New
SqlClient.SqlCommand("SELECT child_ref, father_ref,
type_cur From cust_comp WHERE (type_cur = 'USD') AND (father_ref
= '4111')")
Dim
DAdapter As
System.Data.SqlClient.SqlDataAdapter =
New
SqlClient.SqlDataAdapter(selectCMD)
Dim
DSet As
New
DataSet
' New Account Id
selectCMD.Connection() =
Me.SqlConnection1
Me.SqlConnection1.Open()
DAdapter.Fill(DSet, "cust_comp")
' cust_comp Table
Me.SqlConnection1.Close()
ThisValue =
Trim(DSet.Tables("cust_comp").Rows(DSet.Tables("cust_comp").Rows.Count
- 1).Item("child_ref"))
'
btnLast_Click(Me.btnLast, e.Empty)
Try
'Clear out the
current edits
Me.BindingContext(Account_DSet1,
"cust_comp").EndCurrentEdit()
Me.BindingContext(Account_DSet1,
"cust_comp").AddNew()
Catch
eEndEdit As
System.Exception
System.Windows.Forms.MessageBox.Show(eEndEdit.Message)
End
Try
Me.Account_DSet_PositionChanged()
SetButtons( False)
Dim
ChildValue As
Integer
= Val(ThisValue) + 1
Me.editchild_ref.Text
= Trim(Str(ChildValue))
Me.editfather_ref.Text
= "4111"
Me.edittype_cur.Text
= "USD"
Me.Panel2.Enabled
= True
Me.editdesc_name.Focus()
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
data
Private
Sub
btnUpdate_Click(ByVal
sender As
System.Object, ByVal
e As
System.EventArgs)
Handles btnUpdate.Click
Try
'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.Panel2.Enabled
= False
Me.btnUpdate.Enabled
= False
SetButtons( True)
'
Me.Account_DSet_PositionChanged()
''
Me.btnNavFirst_Click(Me.btnNavFirst, e.Empty)
''
Me.btnLast_Click(Me.btnLast, 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.Account_DSet =
New
RBT_Accounting_Net.Account_DSet
'Stop any current
edits.
Me.BindingContext(Account_DSet1,
"cust_comp").EndCurrentEdit()
'Get the changes
that have been made to the main dataset.
objDataSetChanges =
CType(Account_DSet1.GetChanges,
RBT_Accounting_Net.Account_DSet)
'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)
Account_DSet1.Merge(objDataSetChanges)
Account_DSet1.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.Account_DSet)
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
End
Class |
| |