代码的特殊问题 [英] Peculiar issue with code

查看:58
本文介绍了代码的特殊问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Private Sub btnInsertSet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsertSet.Click
        btnInsertSet.Enabled = False


        Dim SourceTable As String = "Select * From SetDisplayTable"
        Dim DASource As New OleDb.OleDbDataAdapter
        Dim DSSource As New DataSet

        DASource = New OleDb.OleDbDataAdapter(SourceTable, Con)
        DASource.Fill(DSSource, "DSSourceHere")


        Try

            Dim RowCount As Integer
            For RowCount = 0 To DSSource.Tables(0).Rows.Count - 1
                Dim ItemMaster As String = "SELECT ItemMaster.ID, ItemMaster.ItemSalePrice FROM(ItemMaster) WHERE (((ItemMaster.ID)=" & DSSource.Tables(0).Rows(RowCount).Item(10) & "));"
                Dim DAItemMaster As New OleDb.OleDbDataAdapter
                Dim DSItemMaster As New DataSet

                DAItemMaster = New OleDb.OleDbDataAdapter(ItemMaster, Con)
                DAItemMaster.Fill(DSItemMaster, "DSItemMasterHere")
                If IsDBNull(DSItemMaster.Tables(0).Rows(0).Item(1)) Then
                    'do nothing
                Else
                    If DSItemMaster.Tables(0).Rows(0).Item(1) <> 0 Then
                        '  Dim NetAmt As Decimal = (DSSource.Tables(0).Rows(RowCount).Item(4)) * (DSItemMaster.Tables(0).Rows(0).Item(1))   'Qty * Rate
                        Dim NetAmt As Decimal = (DSSource.Tables(0).Rows(RowCount).Item(4)) * (DSItemMaster.Tables(0).Rows(0).Item(1))   'Qty * Rate
                       
                        Dim DiscAmt As Decimal = (NetAmt * DSSource.Tables(0).Rows(RowCount).Item(7)) / 100
                        '  MsgBox(DiscAmt)
                        DSSource.Tables(0).Rows(RowCount).Item(8) = DiscAmt
                        NetAmt = NetAmt - DiscAmt
                        DSSource.Tables(0).Rows(RowCount).Item(9) = NetAmt
                        'DSSource.Tables(0).Rows(RowCount).Item(7) = NetAmt
                    End If
                End If
            Next
            Dim CBSetAmt As New OleDb.OleDbCommandBuilder(DASource)
            DASource.Update(DSSource, "DSSourceHere")
        Catch Ex As Exception
            MsgBox(Ex.Message)
        End Try
        If Con.State = ConnectionState.Closed Then
            Con.Open()
        End If
        Dim InsertInSBDet As String = "INSERT INTO SBDetTemp ( ItemCode, ItemParticulars, ItemDesc, ItemQty, ItemRate, DiscAmt, NetAmt, ItemUniqCode, PerUnit, DiscPer )SELECT SetDisplayTable.ItemCode, SetDisplayTable.ItemName AS ItemParticulars, SetDisplayTable.Desc AS ItemDesc, SetDisplayTable.Quantity AS ItemQty, SetDisplayTable.Rate AS ItemRate, SetDisplayTable.DiscAmt, SetDisplayTable.NetAmount AS NetAmt, SetDisplayTable.ItemUniqCode, ItemMaster.ItemUnit AS PerUnit, SetDisplayTable.DiscPer FROM ItemMaster INNER JOIN SetDisplayTable ON ItemMaster.ID = SetDisplayTable.ItemUniqCode;"
        Command = New OleDb.OleDbCommand(InsertInSBDet, Con)
        Command.ExecuteNonQuery()
        Con.Close()

        btnRefreshSaleDGV.PerformClick()
    End Sub
    Private Sub btnRefreshSaleDGV_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRefreshSaleDGV.Click
        '  frmSalesInvoice.Show()

        '   With frmSalesInvoice
        frmSalesInvoice.UpdateSerialDetailTemp()
        frmSalesInvoice.NewSerialItemEntry()
        frmSalesInvoice.BringToFront()
        frmSalesInvoice.UpdateDGV()
        ' End With
    End Sub

在上面的代码中,一切都按照我的要求运行,但是问题出在底部按钮单击事件中编写的代码中.使用按钮,我以另一种形式调用了一些子过程.这个程序有 被调用时,未调用其他格式的第一,第二和第四过程,或者它们似乎不起作用.BringToFront方法确实起作用,并且我在上述各行之间放置了消息框,以验证是否正在处理这些行.
请注意,该按钮先前不是我的代码的一部分,并且代码本身在其上面的过程中,但是由于它间歇性地停止工作,因此我必须提供该按钮,然后单击一下使代码起作用.

In the above code everything works as per my requirement but the problem arises in the code written in the button click event at the bottom.With the button I call some sub procedures in another form.The problem is that a few times after this procedure has been called,the first,second and fourth procedures in the other form are not called or they do not seem to work.The BringToFront method does work and I have placed message boxes betweeen each of the above lines to verify that the lines are being processed.
Note that the button was earlier not part of my code and the code itself was in the procedure above it but since it intermittantly stopped working,I had to provide that button,clicking which after a while make the codes work.

最初,我怀疑这可能是因为我使用了With块而发生的,但是过一会儿单独写入表单名称也会导致相同的问题.

Initially I suspected that it might be happening because I was using the With block but after a while writing the form name individually also causes the same issue.

有人可以为这种奇怪的事件序列提供解决方案或建议原因.

Can someone offer a solution or suggest a reason for this strange sequence of events.

哈利德.


推荐答案

听起来像是由于正在处理跨表单(即进入其他线程)而遇到线程问题.

Sounds like you are hitting a threading issue since you are working cross-forms, i.e. into other threads.

也许您应该考虑使子例程成为线程安全的.

Maybe you should look into making the subroutines threadsafe.


这篇关于代码的特殊问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆