Hi, I'm having a problem with my forms. Basically I have one form that adds,deletes,updates transactions that are made when a registered member makes a request. Doing this then gets saved in the database under a transaction table.

I then have another form which then calculates my transactions based on when the member returns the DVD or CD. However, if say for example I wish to delete a transaction record, the form that does the calculation of the fines doesn't update itself.

How can I solve this? If im able to create a refresh button on the fines form would this help and if so how will it work as my form contains 1 combo box , 5 text boxes
and 1 date picker(however the date picker is not linked to the database)?

1)This coding here is to do with "Adding,updating, deleting and saving Transaction":

Public Class PDL_Add_Transaction_Form
    Dim flag As Integer
    Dim dr As DataRow
    Dim dt As DataTable
    Dim transid As String
    Dim bm As BindingManagerBase
    Dim confirm1, confirm2 As DialogResult

    Private Sub PDL_Add_Transaction_Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SqlDATransAdd.Fill(DataSetTransAdd1, "trnsaction")
        bm = Me.BindingContext(DataSetTransAdd1, "trnsaction")
        bm.Position = 0
        cbTID.DropDownStyle = ComboBoxStyle.DropDownList
        btnSave.Enabled = False
        txtAID.ReadOnly = True
        txtIsDate.ReadOnly = True
        txtMID.ReadOnly = True
        txtRDate.ReadOnly = True
        txtAID.BackColor = Color.White
        txtIsDate.BackColor = Color.White
        txtMID.BackColor = Color.White
        txtRDate.BackColor = Color.White

    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        cbTID.DropDownStyle = ComboBoxStyle.DropDown
        txtAID.ReadOnly = False
        txtIsDate.ReadOnly = False
        txtMID.ReadOnly = False
        txtRDate.ReadOnly = False
        btnMainMenu.Enabled = False
        btnTMenu.Enabled = False
        btnAdd.Enabled = False
        btnUpdate.Enabled = False
        btnDelete.Enabled = False
        btnFirst.Enabled = False
        btnNext.Enabled = False
        btnPrev.Enabled = False
        btnLast.Enabled = False
        btnSave.Enabled = True
        txtMID.Text = ""
        txtAID.Text = ""
        txtIsDate.Text = ""
        txtRDate.Text = ""
        flag = 1
        Dim ctr, len As Integer
        Dim memidval As String
        dt = DataSetTransAdd1.Tables("trnsaction")
        len = (dt.Rows.Count - 1)
        dr = dt.Rows(len)
        transid = dr("trnsaction_id")
        memidval = Mid(transid, 2, 3)
        ctr = CInt(memidval)
        If ctr >= 1 And ctr < 9 Then
            ctr = ctr + 1
            cbTID.Text = "T00" & ctr
        ElseIf ctr >= 9 And ctr < 99 Then
            ctr = ctr + 1
            cbTID.Text = "T0" & ctr
        ElseIf ctr >= 99 Then
            ctr = ctr + 1
            cbTID.Text = "T" & ctr
        End If
        cbTID.Enabled = False
    End Sub

    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        cbTID.DropDownStyle = ComboBoxStyle.DropDown
        txtAID.ReadOnly = False
        txtIsDate.ReadOnly = False
        txtMID.ReadOnly = False
        txtRDate.ReadOnly = False
        btnMainMenu.Enabled = False
        cbTID.Enabled = False
        btnTMenu.Enabled = False
        btnFirst.Enabled = False
        btnNext.Enabled = False
        btnPrev.Enabled = False
        btnLast.Enabled = False
        btnAdd.Enabled = False
        btnUpdate.Enabled = False
        btnDelete.Enabled = False
        btnSave.Enabled = True
        transid = cbTID.Text
        flag = 2
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        txtAID.ReadOnly = True
        txtIsDate.ReadOnly = True
        txtMID.ReadOnly = True
        txtRDate.ReadOnly = True
        txtAID.BackColor = Color.White
        txtIsDate.BackColor = Color.White
        txtMID.BackColor = Color.White
        txtRDate.BackColor = Color.White
        btnMainMenu.Enabled = False
        btnTMenu.Enabled = False
        btnFirst.Enabled = False
        btnNext.Enabled = False
        btnPrev.Enabled = False
        btnLast.Enabled = False
        btnAdd.Enabled = False
        btnUpdate.Enabled = False
        btnDelete.Enabled = False
        btnSave.Enabled = True
        transid = cbTID.Text
        dt = DataSetTransAdd1.Tables("trnsaction")
        dr = dt.Rows.Find(transid)
        flag = 3
        confirm1 = MessageBox.Show("Are you sure that you wish to delete this record?", "MessageBox", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        If confirm1 = Windows.Forms.DialogResult.Yes Then
            btnSave.Enabled = True
            cbTID.Enabled = False
            txtAID.Enabled = False
            txtIsDate.Enabled = False
            txtMID.Enabled = False
            txtRDate.Enabled = False

        Else
            confirm1 = Windows.Forms.DialogResult.No
            btnFirst.Enabled = True
            btnNext.Enabled = True
            btnPrev.Enabled = True
            btnLast.Enabled = True
            btnAdd.Enabled = True
            btnUpdate.Enabled = True
            btnDelete.Enabled = True
            btnSave.Enabled = False
            txtAID.ReadOnly = True
            txtIsDate.ReadOnly = True
            txtMID.ReadOnly = True
            txtRDate.ReadOnly = True
            txtAID.BackColor = Color.White
            txtIsDate.BackColor = Color.White
            txtMID.BackColor = Color.White
            txtRDate.BackColor = Color.White
            Return

        End If

    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        'Adding Button:
        If flag = 1 Then
            dt = DataSetTransAdd1.Tables("trnsaction")
            dr = dt.NewRow()
            dr(0) = cbTID.Text
            dr(1) = txtMID.Text
            dr(2) = txtAID.Text
            dr(3) = txtIsDate.Text
            dr(4) = txtRDate.Text
            dt.Rows.Add(dr)
            cbTID.Enabled = True
            MessageBox.Show("Adding New Transaction Details Successfull.", "MessageBox", MessageBoxButtons.OK, MessageBoxIcon.Information)
            cbTID.DropDownStyle = ComboBoxStyle.DropDownList
            btnMainMenu.Enabled = True
            btnTMenu.Enabled = True
            btnAdd.Enabled = True
            btnUpdate.Enabled = True
            btnDelete.Enabled = True
            btnFirst.Enabled = False
            btnNext.Enabled = False
            btnPrev.Enabled = False
            btnLast.Enabled = False
            btnSave.Enabled = False
            txtAID.ReadOnly = True
            txtIsDate.ReadOnly = True
            txtMID.ReadOnly = True
            txtRDate.ReadOnly = True
            txtAID.BackColor = Color.White
            txtIsDate.BackColor = Color.White
            txtMID.BackColor = Color.White
            txtRDate.BackColor = Color.White

            'Update Button:
        ElseIf flag = 2 Then
            dt = DataSetTransAdd1.Tables("trnsaction")
            dr = dt.Rows.Find(transid)
            dr(0) = cbTID.Text
            dr(1) = txtMID.Text
            dr(2) = txtAID.Text
            dr(3) = txtIsDate.Text
            dr(4) = txtRDate.Text
            dr.EndEdit()
            cbTID.Enabled = True
            MessageBox.Show("Updating Transaction Details Successfull.", "MessageBox", MessageBoxButtons.OK, MessageBoxIcon.Information)
            cbTID.DropDownStyle = ComboBoxStyle.DropDownList
            btnMainMenu.Enabled = True
            btnTMenu.Enabled = True
            btnAdd.Enabled = True
            btnUpdate.Enabled = True
            btnDelete.Enabled = True
            btnFirst.Enabled = True
            btnNext.Enabled = True
            btnPrev.Enabled = True
            btnLast.Enabled = True
            btnSave.Enabled = False
            txtAID.ReadOnly = True
            txtIsDate.ReadOnly = True
            txtMID.ReadOnly = True
            txtRDate.ReadOnly = True
            txtAID.BackColor = Color.White
            txtIsDate.BackColor = Color.White
            txtMID.BackColor = Color.White
            txtRDate.BackColor = Color.White


            'Delete Button:
        ElseIf flag = 3 Then
            btnSave.Enabled = True
            dr.Delete()
            confirm2 = MessageBox.Show("Deleting transaction Details Successfull", "MessageBox", MessageBoxButtons.OK, MessageBoxIcon.Information)
            cbTID.DropDownStyle = ComboBoxStyle.DropDownList
            btnSave.Enabled = False

        End If
        btnMainMenu.Enabled = True
        btnTMenu.Enabled = True
        btnAdd.Enabled = True
        btnUpdate.Enabled = True
        btnDelete.Enabled = True
        btnFirst.Enabled = True
        btnNext.Enabled = True
        btnPrev.Enabled = True
        btnLast.Enabled = True
        btnSave.Enabled = False
        cbTID.Enabled = True
        txtAID.Enabled = True
        txtIsDate.Enabled = True
        txtMID.Enabled = True
        txtRDate.Enabled = True
        txtAID.ReadOnly = True
        txtIsDate.ReadOnly = True
        txtMID.ReadOnly = True
        txtRDate.ReadOnly = True
        txtAID.BackColor = Color.White
        txtIsDate.BackColor = Color.White
        txtMID.BackColor = Color.White
        txtRDate.BackColor = Color.White

        flag = 0
        cbTID.Enabled = True
        btnFirst.Enabled = True
        btnNext.Enabled = True
        btnPrev.Enabled = True
        btnLast.Enabled = True
        txtAID.ReadOnly = True
        txtIsDate.ReadOnly = True
        txtMID.ReadOnly = True
        txtRDate.ReadOnly = True
        txtAID.BackColor = Color.White
        txtIsDate.BackColor = Color.White
        txtMID.BackColor = Color.White
        txtRDate.BackColor = Color.White
        SqlDATransAdd.Update(DataSetTransAdd1, "trnsaction")
        SqlDATransAdd.Fill(DataSetTransAdd1, "trnsaction")

    End Sub

    Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
        bm.Position = 0
    End Sub

    Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev.Click
        bm.Position -= 1
    End Sub

    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        bm.Position += 1
    End Sub

    Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
        bm.Position = bm.Count - 1
    End Sub
    Private Sub btnTMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTMenu.Click
        Me.Hide()
        PDL_Transaction_Form.Show()
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        lblDTime.Text = Date.Now.ToString()
    End Sub

    Private Sub btnMainMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMainMenu.Click
        Me.Hide()
        PDL_MainMenu_Form.Show()
    End Sub
End Class

2) This form does "Calculating the transactions":

Public Class PDL_Transaction_Fines_Form
    Dim bm As BindingManagerBase

    Private Sub PDL_Transaction_Fines_Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SqlDAtransFines.Fill(DataSetFinesTrans1, "album")
        bm = BindingContext(DataSetFinesTrans1, "album")
        bm.Position = 0
        cbTID.DropDownStyle = ComboBoxStyle.DropDownList
    End Sub

    Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
        Dim issueD, returnD, mdate As New Date
        Dim memberD As New Integer
        Dim fine, result As New Integer
        If (txtMDate.Text = "".ToString) Or (txtMDate.Text = 0.ToString) Or (txtMDate.Text = "-".ToString) Then
            MessageBox.Show("Invalid entry. Please Try again", "ErrorMessageBox", MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtMDate.Text = ""
            Return
        End If
        issueD = CType(txtIsDate.Text, Date)
        returnD = CType(txtRDate.Text, Date)
        mdate = CType(txtMDate.Text, Date)
        'memberD = txtMDate.Text
        'fine = (memberD - returnD)
        fine = DateDiff(DateInterval.Day, returnD, mdate)
        txtDispFine.Text = fine.ToString
        result = fine
        fine = (result * 10)
        txtFines.Text = "$" & fine
        If (CType(txtDispFine.Text, Integer) <= 0) Then
            MessageBox.Show("No Fine!!!", "NoFineMessageBox", MessageBoxButtons.OK, MessageBoxIcon.Information)
            txtMDate.Text = ""
            txtDispFine.Text = ""
            txtFines.Text = ""
            Return
        Else
            MessageBox.Show("The Fine is :" & " $" & fine & " ,Please pay your fine ASAP!", "FineIssueMessageBox", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            txtMDate.Text = ""
            txtDispFine.Text = ""
            txtFines.Text = ""
            Return
        End If
    End Sub

    Private Sub btnTMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTMenu.Click
        Me.Hide()
        PDL_Transaction_Form.Show()
    End Sub
    Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
        bm.Position = 0
    End Sub

    Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev.Click
        bm.Position -= 1
    End Sub

    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        bm.Position += 1
    End Sub

    Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
        bm.Position = bm.Count - 1
    End Sub

    Private Sub btnMainMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMainMenu.Click
        Me.Hide()
        PDL_MainMenu_Form.Show()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        lblDTime.Text = Date.Now.ToString()
    End Sub
End Class

If anyone can help me with this thanks God Bless.

Recommended Answers

All 3 Replies

please be more specific , there is not that much time to read your all code , please tell me where you have prob and what you really want to do

Regards

You can force your delete/refresh by making the delete form modal and creating a sub procedure that will refresh the data in the parent form.

Hi, I figured this out ,I created a refresh button that linked to the database directly.

Here is the coding:

Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
        Dim conn As New SqlClient.SqlConnection("Data Source=CHETS-TOSHIBA\SQLEXPRESS;Initial Catalog=PlanetDiscLibrary;Integrated Security=True")
        Dim da As New SqlClient.SqlDataAdapter("SELECT  member.member_id, trnsaction.trnsaction_id, album.album_id, album.album_name, trnsaction.issue_date, trnsaction.return_date FROM  member INNER JOIN trnsaction ON member.member_id = trnsaction.member_id INNER JOIN album ON trnsaction.album_id = album.album_id", conn)
        Dim dt As New DataTable

        dt.Clear()
        conn.Open()
        da.Fill(dt)
        DataSetFinesTrans1.Clear()
        SqlDAtransFines.Fill(DataSetFinesTrans1, "album")
        bm = BindingContext(DataSetFinesTrans1, "album")
        bm.Position = 0
        cbTID.DropDownStyle = ComboBoxStyle.DropDownList
        conn.Close()
    End Sub

Thanks for replying anyway....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.