ProductForm.vb |
Public
Class
ProductForm
Inherits System.Windows.Forms.Form
Dim
mbAddNewFlag As
Boolean
= False
Dim
UChange As
Integer
Windows Form Designer generated code |
Private
Sub
ProductForm_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.ProductDSet_PositionChanged()
Me.txttdate.Text
= System.DateTime.Now.ToLongDateString
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")
' ComboBox
control
Me.cmbcurrency.Items.Add("LL")
Me.cmbcurrency.Items.Add("USD")
Me.cmbcurrency.Items.Add("EUR")
Me.cmbcurrency.Items.Add("UK")
Me.cmbcurrency.Items.Add("JAP")
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.ProductDSet
objDataSetTemp =
New RBT_Accounting_Net.ProductDSet
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.
ProductDSet1.Clear()
'Merge the
records into the main dataset.
ProductDSet1.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.ProductDSet)
'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
btnNavFirst_Click(ByVal
sender As
System.Object, ByVal
e As
System.EventArgs)
Handles btnNavFirst.Click
Me.BindingContext(ProductDSet1,
"Product").Position = 0
Me.ProductDSet_PositionChanged()
End
Sub
Private
Sub
btnNavPrev_Click(ByVal
sender As
System.Object, ByVal
e As
System.EventArgs)
Handles btnNavPrev.Click
Me.BindingContext(ProductDSet1,
"Product").Position = (Me.BindingContext(ProductDSet1,
"Product").Position - 1)
Me.ProductDSet_PositionChanged()
End
Sub
Private
Sub
btnNavNext_Click(ByVal
sender As
System.Object, ByVal
e As
System.EventArgs)
Handles btnNavNext.Click
Me.BindingContext(ProductDSet1,
"Product").Position = (Me.BindingContext(ProductDSet1,
"Product").Position + 1)
Me.ProductDSet_PositionChanged()
End
Sub
Private
Sub
btnLast_Click(ByVal
sender As
System.Object, ByVal
e As
System.EventArgs)
Handles btnLast.Click
Me.BindingContext(ProductDSet1,
"Product").Position = (Me.ProductDSet1.Tables("Product").Rows.Count
- 1)
Me.ProductDSet_PositionChanged()
End
Sub
Private
Sub
ProductDSet_PositionChanged()
Me.lblNavLocation.Text
= (((Me.BindingContext(ProductDSet1,
"Product").Position + 1).ToString + " of ") _
+ Me.BindingContext(ProductDSet1,
"Product").Count.ToString)
' Navigation
controls enebled(True or False
If
Me.BindingContext(ProductDSet1,
"Product").Position + 1 = 1
Then
NavigationFP( False)
NavigationNL( True)
ElseIf
Me.BindingContext(ProductDSet1,
"Product").Position + 1 =
Me.BindingContext(ProductDSet1,
"Product").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
Private
Sub
btnAdd_Click(ByVal
sender As
System.Object, ByVal
e As
System.EventArgs)
Handles btnAdd.Click
' chang Table,
SqlCommand & SqlDataAdapter & DataSet controls
Dim
selectCMD As
System.Data.SqlClient.SqlCommand =
New
SqlClient.SqlCommand("SELECT child_ref, father_ref,
type_cur From chang WHERE (type_cur = 'USD') AND (father_ref
= '4111') ORDER BY child_ref")
Dim
DAdapter As
System.Data.SqlClient.SqlDataAdapter =
New
SqlClient.SqlDataAdapter(selectCMD)
Dim
DSet As
New
DataSet
Try
'Clear out the
current edits
Me.BindingContext(ProductDSet1,
"Product").EndCurrentEdit()
Me.BindingContext(ProductDSet1,
"Product").AddNew()
mbAddNewFlag =
True
SetButtons( False)
Panel1.Enabled =
True
lnote1.Visible =
True
Me.txtId.Focus()
Catch
eEndEdit As
System.Exception
System.Windows.Forms.MessageBox.Show(eEndEdit.Message)
End
Try
Me.ProductDSet_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
Private
Sub
txtId_DoubleClick(ByVal
sender As
Object,
ByVal
e As
System.EventArgs)
Handles txtId.DoubleClick
Dim
vrow1 As
Integer
Dim
flag As
Boolean
= False
' Product Table,
SqlCommand & SqlDataAdapter & DataSet controls
Dim
selectCMD1 As
System.Data.SqlClient.SqlCommand =
New
SqlClient.SqlCommand("SELECT prod_id FROM product")
Dim
DAdapter1 As
System.Data.SqlClient.SqlDataAdapter =
New
SqlClient.SqlDataAdapter(selectCMD1)
Dim
DSet1 As
New
DataSet
' Product Table
selectCMD1.Connection() =
Me.SqlConnection1
Me.SqlConnection1.Open()
DAdapter1.Fill(DSet1, "Product")
' Product Table
Me.SqlConnection1.Close()
' Product Table -
the quantity corresponding, Added
For
vrow1 = 0 To
DSet1.Tables("Product").Rows.Count - 1
If
Trim(DSet1.Tables("Product").Rows(vrow1).Item("prod_id"))
= txtId.Text Then
flag = True
Exit
For
End
If
Next
vrow1
If
flag Then
MsgBox("Duplicate Product Id, re-enter",
MsgBoxStyle.Exclamation, Title)
Me.txtId.Text
= ""
Me.txtId.Focus()
Else
Me.cmbcurrency.Focus()
End
If
End
Sub
Private
Sub
cmbcurrency_SelectedIndexChanged(ByVal
sender As
Object,
ByVal
e As
System.EventArgs)
Handles
cmbcurrency.SelectedIndexChanged
' Chang Table,
SqlCommand & SqlDataAdapter & DataSet controls
Dim
selectCMD1 As
System.Data.SqlClient.SqlCommand =
New
SqlClient.SqlCommand("SELECT ch_date, rate_ll, llrate_usd,
rate_eur, rate_eng, rate_jap FROM chang ORDER BY ch_date")
Dim
DAdapter1 As
System.Data.SqlClient.SqlDataAdapter =
New
SqlClient.SqlDataAdapter(selectCMD1)
Dim
DSet1 As
New
DataSet
' Chang Table
selectCMD1.Connection() =
Me.SqlConnection1
Me.SqlConnection1.Open()
DAdapter1.Fill(DSet1, "Chang")
' Chang Table
Me.SqlConnection1.Close()
If
Me.cmbcurrency.Text
= "USD" Then
UChange = 1
ElseIf
Me.cmbcurrency.Text
= "LL" Then
UChange = DSet1.Tables("chang").Rows(DSet1.Tables("chang").Rows.Count
- 1).Item(1)
ElseIf
Me.cmbcurrency.Text
= "EUR" Then
UChange = DSet1.Tables("chang").Rows(DSet1.Tables("chang").Rows.Count
- 1).Item(3)
ElseIf
Me.cmbcurrency.Text
= "UK" Then
UChange = DSet1.Tables("chang").Rows(DSet1.Tables("chang").Rows.Count
- 1).Item(4)
ElseIf
Me.cmbcurrency.Text
= "JAP" Then
UChange = DSet1.Tables("chang").Rows(DSet1.Tables("chang").Rows.Count
- 1).Item(5)
End
If
Me.txtname.Focus()
End
Sub
Private
Sub
txtcostcur_DoubleClick(ByVal
sender As
Object,
ByVal
e As
System.EventArgs)
Handles txtcostcur.DoubleClick
Me.txtunitcost.Text
= Format((Me.txtcostcur.Text
* UChange), "0.00")
Me.txtunitprice.Text
= Format((Me.txtunitcost.Text
+ (Me.txtunitcost.Text
* 0.3)), "0.00")
Me.btnUpdate.Enabled
= True
End
Sub
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.ProductDSet_PositionChanged()
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.ProductDSet =
New
RBT_Accounting_Net.ProductDSet
'Stop any current
edits.
Me.BindingContext(ProductDSet1,
"Product").EndCurrentEdit()
'Get the changes
that have been made to the main dataset.
objDataSetChanges =
CType(ProductDSet1.GetChanges,
RBT_Accounting_Net.ProductDSet)
'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)
ProductDSet1.Merge(objDataSetChanges)
ProductDSet1.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.ProductDSet)
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
Private
Sub
btnclose_Click(ByVal
sender As
System.Object, ByVal
e As
System.EventArgs)
Handles btnclose.Click
Application.Exit()
End
Sub
End
Class |
| |